Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default 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.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default 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 ?



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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 ?


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default need previous row help

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
3-Color Scale Vlookup for Current Month/Previous/Pre-Previous NeoFax Excel Discussion (Misc queries) 2 January 8th 10 07:04 PM
why I can not see all my previous posts? Dream Excel Discussion (Misc queries) 4 December 23rd 09 07:25 PM
previous day tigoda Excel Programming 4 October 17th 06 02:37 PM
Looking at previous columns M3Cobb[_3_] Excel Programming 2 July 12th 05 11:44 AM
Ref:Previous post debra2468[_10_] Excel Programming 0 August 4th 04 09:23 PM


All times are GMT +1. The time now is 09:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"