Select cells with Excel VBA

Closed
Tony - Jun 8, 2010 at 02:34 PM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Jun 8, 2010 at 05:19 PM
Hello,

I'm trying to write a vba script in Excel 2003. I have a table of data starting at cell B4.

I want to select B4:Ix where x is the last row with data entered into it.

How can I do this? My first thought was Range("B4:I65536").End(xlUp).Select but then cell B2 is selected (B1 is empty, B2 is title and B3 is empty).

If anyone can help I'd be really greatful!

1 response

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Jun 8, 2010 at 05:19 PM
Dim Cell As Range 
Dim lMaxRows As Long 

    Set Cell = Cells.Find("*", Cells(1, "A"), SearchOrder:=xlByRows, SearchDirection:=xlPrevious) 
     
    If Cell Is Nothing Then 
       lMaxRows = 1 
     
    Else 
     
       lMaxRows = Cell.Row + 1 
     
    End If 
     
    Set Cell = Nothing
2