Changed cell contents

  • Thread starter Thread starter Mike Donnelly
  • Start date Start date
M

Mike Donnelly

What is the best way to determine when leaving a cell, if
a user had changed the contents

Thanks for your help
 
If by "a user has changed the contents" you mean "a user has made an
entry" (i.e., even if they entered the same value that was already in
the cell), use the Worksheet_Change() event macro. That event fires when
the change is made, however, not when the cell is exited (though they
may happen at the same time).

Otherwise you can save the previous value in a static or public variable
and compare values when the Worksheet_SelectionChange event fires:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Static vOldA1 As Variant
Static bA1Selected As Boolean
If Target.Address(False, False) = "A1" Then
vOldA1 = Target.Value
bA1Selected = True
Else
If bA1Selected Then
bA1Selected = False
With Range("A1")
If vOldA1 <> .Value Then
MsgBox "A1 changed from " & vOldA1 & " to " & .Value
vOldA1 = .Value
End If
End With
End If
End If
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

Back
Top