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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

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