Kai Mou
Kai Mou

Reputation: 406

VBA Find value of second to last row

I'm currently having trouble in VBA with finding the second last value in a row.

I can currently find the last value in the row with End(xlToLeft).Value, but how do I find the value just before that?

I would use the offset function but there are spaces and the worksheet is dynamic so I can't use the offset function. how would I go about doing this?

Upvotes: 1

Views: 680

Answers (2)

Gazza
Gazza

Reputation: 95

not sure of the exact syntax but something like the following

for each cell in cells
    if cell is notnothing then
       ' add your code here to use the value
    end if
next

Upvotes: 0

Gazza
Gazza

Reputation: 95

Why don`t you create a variable for the last column then just set the value to itself -2

e.g dim Lastcolumn as integer Lastcolumn = ActiveSheet.Cells.SpecialCells(xlLastCell).Column Lastcolumn = Lastcolumn - 2

Upvotes: 0

Related Questions