That's what I said and it is working now (Auto-correcting an entry
when user hits enter or "arrows" out of a cell). Using "Target" did
the trick.
> 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.
If I read that, it is strange, but my stuff works ok now.
The original question -- I was trying to use ActiveCell in the _Change
() event handler sub and I was getting the cell changed TO rather
than the cell changed FROM (Enter changes cell). I ASSUMED that if
the _Change() event fires when a value in a cell changes (not all
that poor an assumption) that the cell just changed would still be
the ActiveCell when you are *IN* the _Change() sub... but
Noooooo. Target refers to the cell changed, but ActiveCell is the
new cell. I guess the cell is changed first *THEN* the value is
changed in the previous cell... Crummy Microsoft.