0

How do i find what the last row of of a column that is highlighted? Currently I only know how to find last row that is used.

LastRow = Cells(Rows.Count, 1).End(xlUp).Row
Kellogs
  • 3
  • 2

2 Answers2

2

You are not 100% correct with your statement - with your current code you will get the row number of the last row of column A (that's what the 1 in your statement stands for) - not neccessarily the last row in use of the whole sheet.
If you want to know the last row of a specific column, just change this 1 to the column number you are interested. Probably with "highlighted" you mean the active cell, so that would be

LastRow = Cells(Rows.Count, Activecell.Column).End(xlUp).Row

A rather complete discussion about how to get the last row/column/cell can be found at Find last used cell in Excel VBA


FunThomas
  • 23,043
  • 3
  • 18
  • 34
0

If I have understood your requirement correctly then you will need an approach like this.

lngLastRow = Selection.Cells(Selection.Cells.Count, 1).Row

shrivallabha.redij
  • 5,832
  • 1
  • 12
  • 27