code for cell change not working

  • Thread starter Thread starter Pal
  • Start date Start date
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
 
By default, string comparisons in VBA are case sensitive. Try

If Target.Address = "$N$2" Then
 
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
 
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
 
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
 
Thanks all
I reduced it down to the following that worked.
Pal


Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Address = "$I$2" Then 'my stuff here'
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