Home > Back-end >  finding last row of highlighted cell
finding last row of highlighted cell

Time:11-03

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

CodePudding user response:

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


CodePudding user response:

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

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

  • Related