Message to Tom Ogilvy regarding SelectionChange

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Tom,

Thanks again for the help with the SelectionChange code. One more follow up question if I may. Is this code legal:
----start code-------

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

if Target.Column = 1 then
if Target.Value < Target.offset(0,1).Value then
msgbox "Column 1"
end if
end if

if Target.Column = 5 then
if Target.Value < Target.offset(0,1).Value then
msgbox "Column 5"
end if
end if
End sub

-----end code-----

I have tried this, and only the first "if Target.Column = " statement seems to be recognized. If I run it this way, only targets in column 1 work. If I switch it around, then only targets in column 5 work. And I am not allowed to do more than one "Private Sub Worksheet_Change(ByVal Target As Excel.Range)" statement (I tried this and it told me ambiguous statement). What am I doing wrong? Thanks.

Doug
 
Yes, it is legal. Since it is the change event, it only fires when you edit
a cell - not just select it as was the case when you used selectionChange.
But based on your description, Change sounded like the more appropriate
event.
 
Back
Top