ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   need previous row help (https://www.excelbanter.com/excel-programming/384661-need-previous-row-help.html)

[email protected]

need previous row help
 
I'm trying to figure a way to compare the previous row with the target
row in a worksheet_SelectionChange event
for example.

if previous row < target.row then
call macro
else
exit sub
end if

So my question is How would I go about determining the previous row?
Any help would be great. Thanks


Tim Williams

need previous row help
 
Do you mean you want to compare the entire two rows to see if the contents are identical, or that you just want to compare the row
numbers ?

--
Tim Williams
Palo Alto, CA


wrote in message oups.com...
I'm trying to figure a way to compare the previous row with the target
row in a worksheet_SelectionChange event
for example.

if previous row < target.row then
call macro
else
exit sub
end if

So my question is How would I go about determining the previous row?
Any help would be great. Thanks




Simon Murphy

need previous row help
 
target.row-1 ?

not too sure what you are doing, are you wanting to check the selection and
the previous selection are on the same row
if so you'll need to keep track of the previous selection (or at least its
row) in a static or module level variable.

cheers
Simon

Blog: www.smurfonspreadsheets.net
Website: www.codematic.net Excel development, support and training


wrote in message
oups.com...
I'm trying to figure a way to compare the previous row with the target
row in a worksheet_SelectionChange event
for example.

if previous row < target.row then
call macro
else
exit sub
end if

So my question is How would I go about determining the previous row?
Any help would be great. Thanks




[email protected]

need previous row help
 
I want to run my macro only if my new selection is on a different row
then my old selection. Target.Row - 1 won't work because my new
selection could be any number of rows below or above my old selection.
Target.Row - 1 would only refer to the row directly above the new
selection.


[email protected]

need previous row help
 
I'm new at VBA if I have to keep track of the previous row number in a
static or module level variable can someone walk me through it ?


phillfri

need previous row help
 
[1] Try putting a couple global variables at the top of the Workbook module,
like
Public gOldRow as range
Public gCurRow as range

[2] In the worksheet_selection change event you need to capture the current
row

set gOldRow = gCurRow
set gCurRow = Target.cells(1,1).entirerow

[3] In the worksheet_change event code you can do like

If gCurRow.row < cOldRow.row then
...... do updating .......
end if

There are a variety of ways you can approach this. But this way you have a
'range' copy of the prior record and the current record to work with.






" wrote:

I'm new at VBA if I have to keep track of the previous row number in a
static or module level variable can someone walk me through it ?



[email protected]

need previous row help
 
Okay I tried that and got an Object Variable or With Block Variable
not set error. Any Ideas?



All times are GMT +1. The time now is 05:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com