VBA Set the last row to the First Row with data

decadence

Well-known Member
Joined
Oct 9, 2015
Messages
525
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2010
  5. 2007
Platform
  1. Windows
Hi, Is it possible to set a range from the last row of data to the first row of data found in Columns AA, My data is varied and the row can change where my data starts from. There are no headers and there may be empty/blank cells above the first cell with data in.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try this:
Code:
Sub FindRange()

    Dim fRow As Long
    Dim lRow As Long
    Dim myRange As Range
    
'   Find first row with data
    If Cells(1, "AA") <> "" Then
        fRow = 1
    Else
        fRow = Cells(1, "AA").End(xlDown).Row
    End If
    
'   Find last row with data
    lRow = Cells(Rows.Count, "AA").End(xlUp).Row
    
'   Set range
    If lRow >= fRow Then
        Set myRange = Range(Cells(fRow, "AA"), Cells(lRow, "AA"))
        MsgBox "Range is " & myRange.Address
    Else
        MsgBox "No data in column AA"
    End If
        
End Sub
 
Upvote 0
Thanks Joe4, This is what I was looking to happen, much appreciated
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top