![]() |
Select dynamic range
Dear all,
I would like to select a range starting from cell A1, but the ending cell can be any cell on the worksheet. I am not sure how to program this. Can anyone advise? Thanks in advance! Ivan |
Select dynamic range
Here is the basic code:
Sub fLastCell() LastRow = Cells(Rows.Count, 1).End(xlUp).Row MsgBox "Last Row Number is " & LastRow, , "" LastColumn = Cells(1, Columns.Count).End(xlToLeft).Column LastCell = Cells(LastRow, LastColumn) End Sub You will need to select a column that has contiguous data for Cells(Rows.Count, ?) and a row that has contiguous data for cells(Columns.count, ?) so that the End( ) function works properly. "Ivan" wrote: Dear all, I would like to select a range starting from cell A1, but the ending cell can be any cell on the worksheet. I am not sure how to program this. Can anyone advise? Thanks in advance! Ivan |
Select dynamic range
I forgot to select the range:
Sub fLastCell() LastRow = Cells(Rows.Count, 1).End(xlUp).Row MsgBox "Last Row Number is " & LastRow, , "" LastColumn = Cells(1, Columns.Count).End(xlToLeft).Column LastCell = Cells(LastRow, LastColumn).Address 'Also add Address Range("$A$1:" & LastCell).Select End Sub "Ivan" wrote: Dear all, I would like to select a range starting from cell A1, but the ending cell can be any cell on the worksheet. I am not sure how to program this. Can anyone advise? Thanks in advance! Ivan |
Select dynamic range
Thanks JLGWhiz !
"JLGWhiz" wrote: I forgot to select the range: Sub fLastCell() LastRow = Cells(Rows.Count, 1).End(xlUp).Row MsgBox "Last Row Number is " & LastRow, , "" LastColumn = Cells(1, Columns.Count).End(xlToLeft).Column LastCell = Cells(LastRow, LastColumn).Address 'Also add Address Range("$A$1:" & LastCell).Select End Sub "Ivan" wrote: Dear all, I would like to select a range starting from cell A1, but the ending cell can be any cell on the worksheet. I am not sure how to program this. Can anyone advise? Thanks in advance! Ivan |
All times are GMT +1. The time now is 03:03 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com