Address of Selection Prior to Clicking on a Cell

A

axle

If I have cell b5 selected, and I click on cell e5, is there a way for
VBA to identify that it came from cell b5 before the click?

Code such as this can be set to be triggered when you click on a cell,
but can it tell you what cell it came from?


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("B5")) Is Nothing Then _
Range("B5").Value = 10
End Sub

Thank you,
Chris
 
J

Jacob Skaria

Try the below..

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static pRange As Range
If Not pRange Is Nothing Then MsgBox "Previous target " & pRange.Address

Set pRange = Target
End Sub
 

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