PDA

View Full Version : Solved: lookup previous row in a column



av8tordude
05-10-2011, 12:23 AM
instead of checking the last row in a column, how can I edit this code to check the previous row?

Range("G" & Application.WorksheetFunction.Max(11, Range("G250").End(xlUp).Row)).Value

Bob Phillips
05-10-2011, 12:52 AM
Range("G" & Application.WorksheetFunction.Max(11, Range("G250").End(xlUp).Row - 1)).Value

av8tordude
05-10-2011, 01:04 AM
Hi XLD,

If i'm on row 10, but the last row is 250, I need to check the previous row (i.e. row 9)

Bob Phillips
05-10-2011, 01:14 AM
Then is that not just

Activecell.Row - 1

av8tordude
05-10-2011, 01:17 AM
not really, what you gave was almost there, except is was checking the previous row from the last entry. I need to check the previous row from the row I'm currently on.

Bob Phillips
05-10-2011, 01:38 AM
Sorry, that has lost me. My reading tells me it must be one of those I gave you, you say no - hence confused.

av8tordude
05-10-2011, 05:54 AM
ok...if I'm on row 10, I need the value in row G9.

The code I presented gives me the value in the last filled row. so, If the last filled row is 150, it gives the value in G150; if the last filled row is 239, it gives me the value in G239.

What I'm looking for is if I'm on row 10, i need the value in G9. If I'm on row 40, I need the value in G39.

Bob Phillips
05-10-2011, 07:31 AM
As I said, Activecell.Row - 1


MsgBox Cells(Activecell.Row - 1, "G").Value

av8tordude
05-10-2011, 12:40 PM
I got it. Thank you xld