Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run Macro based on IF
I want to run a macro if cell a1 does not equal b1.
Private Sub Worksheet_Change(ByVal Target As Range) If (a1 < b1) Then Macro1 End If End Sub When I use an equal sign the macro runs every time and when I use the not equal it won't run at all. Thanks for the help! -- Thanks, Nikki |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run Macro based on IF
Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1:B1" '<== change to suit On Error GoTo ws_exit Application.EnableEvents = False If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then If Me.Range("A1").Value < Me.Range("B1").Value Then Call macro1 End If End If ws_exit: Application.EnableEvents = True End Sub -- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "Nikki" wrote in message ... I want to run a macro if cell a1 does not equal b1. Private Sub Worksheet_Change(ByVal Target As Range) If (a1 < b1) Then Macro1 End If End Sub When I use an equal sign the macro runs every time and when I use the not equal it won't run at all. Thanks for the help! -- Thanks, Nikki |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run Macro based on IF
You would use a worksheet change if you are changing a1 or b1
Private Sub Worksheet_Change(ByVal Target As Range) If Target < Range("b1") Then Call mymacro 'if? you really want to fire with ANY change use 'If Range("a1") < Range("b1") Then Call mymacro End Sub Sub mymacro() MsgBox "hi" End Sub -- Don Guillett Microsoft MVP Excel SalesAid Software "Nikki" wrote in message ... I want to run a macro if cell a1 does not equal b1. Private Sub Worksheet_Change(ByVal Target As Range) If (a1 < b1) Then Macro1 End If End Sub When I use an equal sign the macro runs every time and when I use the not equal it won't run at all. Thanks for the help! -- Thanks, Nikki |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run Macro based on IF
Thank you Bob-
It worked as I hoped this time. -- Thanks, Nikki "Bob Phillips" wrote: Private Sub Worksheet_Change(ByVal Target As Range) Const WS_RANGE As String = "A1:B1" '<== change to suit On Error GoTo ws_exit Application.EnableEvents = False If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then If Me.Range("A1").Value < Me.Range("B1").Value Then Call macro1 End If End If ws_exit: Application.EnableEvents = True End Sub -- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "Nikki" wrote in message ... I want to run a macro if cell a1 does not equal b1. Private Sub Worksheet_Change(ByVal Target As Range) If (a1 < b1) Then Macro1 End If End Sub When I use an equal sign the macro runs every time and when I use the not equal it won't run at all. Thanks for the help! -- Thanks, Nikki |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Run macro based on range value | Excel Discussion (Misc queries) | |||
Insert a row based on a macro | Excel Discussion (Misc queries) | |||
How to run a macro based on an If formula? | Excel Programming | |||
Run macro based on cell value | Excel Programming | |||
Run A Macro based on changes in cell | Excel Programming |