Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Jaymz Brown   on Oct 11 In MS Office Category.

  
Question Answered By: Blandina Garcia   on Oct 11

The change  handler actually has a Target parameter. There's a nice little
example in the help that sets the text of every changed cell  to blue.

The code from the help:

Private Sub Worksheet_Change(ByVal Target As Range)
Target.Font.ColorIndex = 5
End Sub

Being a perverse type, I decided to lock things up a bit. My change to the
sub

Private Sub Worksheet_Change(ByVal Target As Range)
Target.Font.ColorIndex = 5
Target.Activate
End Sub

It still turns it blue, but immediately reactivates it too.

Adding this to the code

MsgBox Target.Value & " vs " & ActiveCell.Value

throws up a problem, though.

Active cell is empty, cell to the right is also empty. Type A and hit right
arrow. MsgBox gives "A vs". Go back. Type B and hit enter  (assuming you
have enter set not to move the cursor). MsgBox gives "B vs B".

I.e. Target has the new value, not the old value. I don't remember the
original question, so am not sure whether this is a problem or not.

Share: 

 

This Question has 13 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Capturing a change BEFORE leaving a cell Or get search suggestion and latest updates.


Tagged: