SelectionChange event

G

Guest

When I change selectio in a worksheet, the range that I select is passed to
the SelectionChange event as Target. How can I identify the range that I have
changed from?
 
T

Tom Ogilvy

You would need to put in a static variable in the selectionchange event and
update it as you exit the selectionchange event.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim oldSelection as Static

' code that does things


set OldSelection = Target

End Sub

if you will have to use this value on the very first selectionchange, then
you will need to make it a public variable in a general module and
initialize it in the Workbook_Open event.
 
G

Guest

Thanks Tom, That makes sense.

Tom Ogilvy said:
You would need to put in a static variable in the selectionchange event and
update it as you exit the selectionchange event.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim oldSelection as Static

' code that does things


set OldSelection = Target

End Sub

if you will have to use this value on the very first selectionchange, then
you will need to make it a public variable in a general module and
initialize it in the Workbook_Open event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top