Search code examples
excelrangevariable-assignmentexcel-2003vba

Can't assign range using .End(xlDown) in Excel VBA?


I've inherited some VBA code (non-.NET, Excel 2003) I have to modify. I want to obtain a handle on a cell range but VBA doesn't like my syntax, saying 'Run-time error 424: Object required'.

When running this code it highlights the line assigning streamsTotal.

Private Sub totalStreams()

    Dim streams As Range, streamsTotal As Range

    ' Select streams data range
    Set streams = Range("H8").End(xlDown)

    ' reference cell 2 cells below last stream row
    Set streamsTotal = streams.Offset(2, 0)

End Sub

I'm struggling to find my answer in Google and previous questions here. Thanks.


Solution

  • Turns out the cell range I was attempting to select was empty.