VBA syntax question

M

Matt

I am using the following to automatically run a particular code (xyz)
if a cell (A1) becomes >10.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not Application.Intersect(Target, Range("A1")) Is Nothing Then
If Target.Value > 10 Then
MsgBox "xyz"
End If
End If
End Sub

What if I want "xyz" to run not just if cell A1 >10 but if A2 >10 as
well? Or better yet, for each value in the entire range A:A that >10,
the code xyz will run.
 
S

Steve

I am using the following to automatically run a particular code (xyz)
if a cell (A1) becomes >10.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not Application.Intersect(Target, Range("A1")) Is Nothing Then
If Target.Value > 10 Then
MsgBox "xyz"
End If
End If
End Sub

What if I want "xyz" to run not just if cell A1 >10 but if A2 >10 as
well? Or better yet, for each value in the entire range A:A that >10,
the code xyz will run.



Adjust the range to the following


Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not Application.Intersect(Target, Range("A:A")) Is Nothing Then
If Target.Value > 10 Then
MsgBox "xyz"
End If
End If
End Sub


Steve
 
M

Mike H

Perhaps

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not Intersect(Target, Range("A:A")) Is Nothing Then
If Target.Value > 10 Then
MsgBox "xyz"
End If
End If
End Sub

Mike
 

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

Top