VBA syntax question
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. |
VBA syntax question
On 5 Dec, 14:56, Matt wrote:
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 |
VBA syntax question
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 "Matt" wrote: 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. |
All times are GMT +1. The time now is 06:01 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com