Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to refer to the previous target

Hi,
Probably a dumb question... I'm changing the colour of cells based on what
the user inputs (too many options for conditional formatting).
Within the "worksheet change" event, I know that "target" is the cell the
user is moving to. How do I reference the cell the user is moving from?
TIA
Damien


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default How to refer to the previous target

We need to remember where we came from:

Dim WhereWasI As String
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If WhereWasI = "" Then
WhereWasI = Target.Address
End If
MsgBox ("we came from " & WhereWasI)
MsgBox ("we now reside at " & Target.Address)
WhereWasI = Target.Address
End Sub

--
Gary''s Student - gsnu200908


"Damien McBain" wrote:

Hi,
Probably a dumb question... I'm changing the colour of cells based on what
the user inputs (too many options for conditional formatting).
Within the "worksheet change" event, I know that "target" is the cell the
user is moving to. How do I reference the cell the user is moving from?
TIA
Damien


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default How to refer to the previous target

How do I reference the cell the user is moving from?

Hi. Just another idea is to have Excel internally remember where we were.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.Goto Target
End Sub

Then, you access the address via...

Function PreviousAddress()
PreviousAddress = Application.PreviousSelections(2).Address
End Function


Sub WhereWasIQ()
MsgBox PreviousAddress
End Sub


Note that if you want to "Go Back" to where you were, don't forget to
turn off Events...

Sub GoBack()
With Application
.EnableEvents = False
.Goto Range(.PreviousSelections(2).Address)
.EnableEvents = True
End With
End Sub

= = = = = = = = = = = = =
HTH
Dana DeLouis


Gary''s Student wrote:
We need to remember where we came from:

Dim WhereWasI As String
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If WhereWasI = "" Then
WhereWasI = Target.Address
End If
MsgBox ("we came from " & WhereWasI)
MsgBox ("we now reside at " & Target.Address)
WhereWasI = Target.Address
End Sub


Damien McBain" wrote:
Hi,
Probably a dumb question... I'm changing the colour of cells based

on what
the user inputs (too many options for conditional formatting).
Within the "worksheet change" event, I know that "target" is the

cell the
user is moving to. How do I reference the cell the user is moving from?
TIA
Damien


.

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
How to refer cell E53 from the previous (=next left) worksheet? Jeff Korn Excel Discussion (Misc queries) 2 June 13th 08 06:48 PM
How to refer cell E53 from the previous (=next left) worksheet? Jeff Korn Excel Programming 2 June 13th 08 06:48 PM
Refer to Previous or Next Sheet build Excel Worksheet Functions 3 October 18th 07 05:38 AM
Refer to the previous worksheet in a formula Shazzer Excel Worksheet Functions 3 December 15th 06 02:07 PM
Worksheet Change Event- Refer to Target Address By Name Jm Excel Programming 2 May 21st 04 02:34 AM


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

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

About Us

"It's about Microsoft Excel"