Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Spreadsheets (https://www.askmehelpdesk.com/forumdisplay.php?f=395)
-   -   How do you reference the last row # as a variable when the number of rows changes? (https://www.askmehelpdesk.com/showthread.php?t=439409)

  • Jan 26, 2010, 11:11 AM
    WesB
    How do you reference the last row # as a variable when the number of rows changes?
    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.)
  • Jan 26, 2010, 03:13 PM
    JBeaucaire

    This is how I do it:

    Store the last row as a variable:
    Code:

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

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

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

    Does that get you started?
  • Jan 26, 2010, 04:36 PM
    WesB

    JB,
    The first option looks like the answer I needed.
    Many Thanks!
    Wes

  • All times are GMT -7. The time now is 11:02 AM.