Find last row and column in a selected range
Fullers,
Be careful with Activecell - it isn't always the top-left cell:
Sub Test()
SelectionAddress = Selection.Address
FirstRow = Selection(1).Row
FirstColumn = Selection(1).Column
LastRow = FirstRow + Selection.Rows.Count - 1
LastColumn = FirstColumn + Selection.Columns.Count -1
'or
'LastRow = Selection(Selection.Cells.Count).Row
'LastColumn = Selection(Selection.Cells.Count).Column
End Sub
HTH,
Bernie
MS Excel MVP
"fullers" wrote in message
...
I want to be able to have a user highlight a range of cells and then run a
macro. What I need from this macro is to obtain the range address, the first
row & column and the last row & column.
At the moment I can get the address and the first row, column with the
following macro:
Sub Test()
SelectionAddress = Selection.Address
FirstRow = ActiveCell.Row
FirstColumn = ActiveCell.Column
End Sub
I cannot figure out how to get the last row, column. Any ideas?
Thanks in advance.
|