Link to home
Create AccountLog in
Avatar of Kevin Willyerd
Kevin WillyerdFlag for United States of America

asked on

Excel : Best way to select a range with a variable number of rows in a macro

Need to set range from imported data where the number of rows varies.
PetzCoupons.xlsx
PetzCode.txt
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

You may try this.....
Dim LastRow As Long
'last row with data in any column on the sheet
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

'last row with data in column E
LastRow = Cells(Rows.Count, "E").End(xlUp).Row

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Try this:

Dim FullRange as Range

Set FullRange=Range("A1").CurrentRegion

Open in new window

Avatar of Kevin Willyerd

ASKER

Thank you for the help.