Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default 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
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
Run macro based on range value saman110 via OfficeKB.com Excel Discussion (Misc queries) 1 January 11th 08 01:28 AM
Insert a row based on a macro Mindie Excel Discussion (Misc queries) 1 October 18th 05 08:05 PM
How to run a macro based on an If formula? Bob123 Excel Programming 1 January 19th 05 04:27 PM
Run macro based on cell value nowfal[_3_] Excel Programming 2 September 15th 04 10:39 AM
Run A Macro based on changes in cell Pete Excel Programming 2 December 2nd 03 03:08 PM


All times are GMT +1. The time now is 03:41 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"