code for cell change not working

P

Pal

I have the following code in a worksheet.
I am looking to test for a change in cell N2.
But nothing happens. If N2=5 and I change it to 10 then I thought the msgbox
would
popup but it does not.
Thanks
Pal


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$n$2" Then
MsgBox "Do something "
End If
End Sub
 
J

JE McGimpsey

By default, string comparisons in VBA are case sensitive. Try

If Target.Address = "$N$2" Then
 
G

Gord Dibben

Pal

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Target.Range("N2") Is Nothing Then
MsgBox "Do something "
End If
End Sub

Gord Dibben Excel MVP
 
T

Tom Ogilvy

Believe Gorden meant:

Private Sub Worksheet_Change(ByVal Target As Range)
if Target.count > 1 then exit sub
If Not Intersect(Target, Range("N2")) Is Nothing Then
MsgBox "Do something "
End If
End Sub
 
G

Gord Dibben

Tom

Other than the fact that my code pops up the message for every cell on the
sheet, what's the problem?<g>

Thanks for the correction. Poor testing.

Gord
 
Top