ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find last row and column in a selected range (https://www.excelbanter.com/excel-programming/379796-re-find-last-row-column-selected-range.html)

Bernie Deitrick

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.





All times are GMT +1. The time now is 07:49 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com