PDA

View Full Version : Set Range Using a Function



Jordan.Smith
12-17-2019, 12:22 PM
Trying to set the range via a function. Getting a 424 error


'Being Called here
Set findRng = FindFunction.SetRange(1, 1, 1, 100, WS)

'Function that should return the range
Function SetRange(firstRow As Long, firstColumn As Long, lastRow As Long, lastColumn As Long, WS As Worksheet)
SetRange = WS.range(WS.Cells(firstRow, firstColumn), WS.Cells(lastRow, lastColumn))

End Function

Paul_Hossler
12-17-2019, 01:41 PM
Try this



Option Explicit




Sub test()
Dim r As Range


Set r = SetRange(2, 2, 26, 26, ActiveSheet)

MsgBox r.Address




End Sub




'Function that should return the range
Function SetRange(firstRow As Long, firstColumn As Long, lastRow As Long, lastColumn As Long, WS As Worksheet) As Range
With WS
Set SetRange = Range(.Cells(firstRow, firstColumn), .Cells(lastRow, lastColumn))
End With
End Function