Log in

View Full Version : How do you reference the last row # as a variable when the number of rows changes?


WesB
Jan 26, 2010, 11:11 AM
I download constantly changing financial worksheets, each with a different number of rows of information. I need to reference the last row in a specific column as a variable to use as a variable cell reference in Excel VBA, so that I can format the entire column from the last row, formatting upward. (i.e. using the value of the row number in ActiveCell.SpecialCells(xlLastCell).row, and using that with the specific column name. e.g. "P"rownumbervariable.)

JBeaucaire
Jan 26, 2010, 03:13 PM
This is how I do it:

Store the last row as a variable:

Dim LR as Long
LR = Range("P" & Rows.Count).End(xlUp).Row

Store the VALUE of the last cell with data in a column:

Dim MyVal as String
MyVal = Range("P" & Rows.Count).End(xlUp).Value

Does that get you started?

WesB
Jan 26, 2010, 04:36 PM
JB,
The first option looks like the answer I needed.
Many Thanks!
Wes