How to retrieve the last selected cell before SelectionChange even

F

Frank Krogh

I am using the SelectionChange event like this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target(1, 1), Range("m1:m1")) Is Nothing Then Exit Sub
....
End Sub

My question is if it's a way to retrieve which cell was selected before the
M1 cell is selected?

Regards

Frank Krogh
 
P

Per Jessen

Hi Frank

Here's a way to do it:

Dim LastSelected As String
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Intersect(Target(1, 1), Range("m1:m1")) Is Nothing Then GoTo XIT
MsgBox LastSelected
'...
XIT:
LastSelected = Target.Address
End Sub

Regards,
Per
 
F

Frank Krogh

Thank you for the solution.

Frank

Per Jessen said:
Hi Frank

Here's a way to do it:

Dim LastSelected As String
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Intersect(Target(1, 1), Range("m1:m1")) Is Nothing Then GoTo XIT
MsgBox LastSelected
'...
XIT:
LastSelected = Target.Address
End Sub

Regards,
Per
 

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