I'm trying to figure out a 1004 error I'm getting in my Excel macro. The line for set numRange
fails if I use the Range(Cells())
format, but succeeds if I use an explicit Range call (i.e. Range("b2")
).
Further down the function, I use the same format (and the same variable name), and it works like a charm.
Any help would be appreciated!
Function GetCopyRange(wbName, wsIndex, vnIndex)
Dim rowsCounter As Integer
Dim numRows As Integer
Dim numCols As Integer
Dim numRange As Range
rowsCounter = 6 'GetStartCell()
Set numRange = Workbooks(wbName).Worksheets(wsIndex).Range(Cells(rowsCounter, 2)) 'This line fails
[ ... ]
Set GetCopyRange = Workbooks(wbName).Worksheets(wsIndex).Range(Cells(rowsCounter, 3), Cells(numRows, numCols)) 'This line succeeds
End Function
Edit: The error I'm getting is a "1004", Application-defined or object-defined error