Select cells with Excel VBA

Closed
Tony - 8 Jun 2010 à 14:34
rizvisa1 Posts 4478 Registration date Thursday 28 January 2010 Status Contributor Last seen 5 May 2022 - 8 Jun 2010 à 17:19
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!
Related:

1 response

rizvisa1 Posts 4478 Registration date Thursday 28 January 2010 Status Contributor Last seen 5 May 2022 766
8 Jun 2010 à 17:19
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