#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 60
Default 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.



  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 32
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default 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.




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
question about syntax in a simple macro... Dave F Excel Discussion (Misc queries) 3 November 3rd 06 02:12 PM
syntax question Giselle Excel Worksheet Functions 4 January 29th 06 01:59 AM
BringToFront syntax question RAP Charts and Charting in Excel 2 August 28th 05 01:34 AM
Data Validation Syntax Question Jim & Gail Excel Discussion (Misc queries) 2 April 7th 05 04:17 AM
syntax question - cell references in VB code needyourhelp New Users to Excel 1 March 2nd 05 08:52 PM


All times are GMT +1. The time now is 09:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"