SheetSelectionChange Event find out previosly selected cell

A

Anton Sommer

Hello folks,

when the selection has changed in the grid the Event SheetSelectionChange is
thrown. Is there a possibility to tell what cell was previosly selected?


Thanks,


Anton
 
E

Earl Kiosterud

Anton,

You can keep track of it yourself:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static OldCell As Range
If Not OldCell Is Nothing Then ' not first time
MsgBox "The old cell is " & OldCell.Address _
& "And it contained " & OldCell
End If

Set OldCell = Target
End Sub


Your code goes where the MsgBox line is. You use the OldCell object as a
range. It's the previous cell.
 
E

Earl Kiosterud

Anton,

It occurs to me that the old multiple-cell selection would confound this.
You might want to change the last line to:

Set OldCell = ActiveCell

Earl Kiosterud
www.smokeylake.com
 

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