Link to home
Start Free TrialLog in
Avatar of willie108
willie108

asked on

macro to select range

Hi. I tried recording a macro with relative references turned on.
I want to select a range that could have a varying number of rows except for the last row. I got the code attached but it has the references B46 which would not work if there were a different number of row. Anyone know what change to make?
Thank you.
Sub Macro2()
'
' Macro2 Macro
'

'
    Range("A1").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range("A1:B46").Select
End Sub

Open in new window

Avatar of Norie
Norie

Try this.
Range(Range("A1"), Range("A1").End(xlDown).End(xlToRight)).Select

Open in new window

Note, in Excel VBA you rarely, if ever, need to select something.
Avatar of willie108

ASKER

Thanks. I need to not select the last row. I want to select the whole range except the last row of the range.
ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks