Responding to cell events in Excel

  • Thread starter Thread starter Angus Comber
  • Start date Start date
A

Angus Comber

Hello

I want to do the following:

A) When I move away from a cell - ie by tabbing or moving with mouse - I
want to be able to check the contents of the previously selected cell.

B) When I move away from a cell - as above - I want to be able to check the
contents of the cell moved to.

So I need a BeforeMoveAway event and a JustMovedToCell event or similar.

Can anyone help because I am finding this tricky

Angus Comber
(e-mail address removed)
 
Angus,

Use the SelectionChange event procedure. Put the following code in the code
module for the appropriate worksheet.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static PrevRange As Range
If Not PrevRange Is Nothing Then
MsgBox "PrevRange: " & PrevRange.Address & vbCrLf & _
"Current Range: " & Target.Address
End If
Set PrevRange = Target
End Sub

PrevRange will refer to the cell that was selected before changing the
selection, and Target will refer to the currently selected range.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 
Back
Top