Help with a conditional macro

  • Thread starter Jerry Eggleston
  • Start date
J

Jerry Eggleston

I have seen something like this here before but can't seem to searc
correctly for it. Say I have a city name in cell A4. Then I input
city into cell B4. If there entries match I would like nothing t
happen. however if a different city is entered, I would like to run
macro. I'm sure that I have seen a similar question asked here but ca
not remember when.


Any help would be appreciated.



Jerry Egglesto
 
L

L. Howard Kittle

Hi Jerry,

This may get you started.

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A4").Value = Range("B4") Then Exit Sub
If Range("A4").Value <> Range("B4") Then
TheMacro
End If
End Sub

Sub TheMacro()
MsgBox "The cities are not the same"
End Sub

Regards,
Howard
 
E

Earl Kiosterud

Howard,

This will run and issue its message (if they don't match) any time a change
is made to any cell on that worksheet. If it's to do so only when one of
the two city cells has been changed, you could add:

Private Sub Worksheet_Change(ByVal Target As Range)
If not intersect(target, Range("A4:B4") is nothing then
If Range("A4").Value = Range("B4") Then Exit Sub
If Range("A4").Value <> Range("B4") Then
TheMacro
End If
End if
End Sub

--
Earl Kiosterud
mvpearl omitthisword at verizon period net
-------------------------------------------

L. Howard Kittle said:
Hi Jerry,

This may get you started.

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A4").Value = Range("B4") Then Exit Sub
If Range("A4").Value <> Range("B4") Then
TheMacro
End If
End Sub

Sub TheMacro()
MsgBox "The cities are not the same"
End Sub

Regards,
Howard


message news:[email protected]...
 
L

L. Howard Kittle

Hi Earl,

That makes sense and is probably what the OP wanted.

Regards,
Howard

Earl Kiosterud said:
Howard,

This will run and issue its message (if they don't match) any time a change
is made to any cell on that worksheet. If it's to do so only when one of
the two city cells has been changed, you could add:

Private Sub Worksheet_Change(ByVal Target As Range)
If not intersect(target, Range("A4:B4") is nothing then
If Range("A4").Value = Range("B4") Then Exit Sub
If Range("A4").Value <> Range("B4") Then
TheMacro
End If
End if
End Sub

--
Earl Kiosterud
mvpearl omitthisword at verizon period net
-------------------------------------------

L. Howard Kittle said:
Hi Jerry,

This may get you started.

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A4").Value = Range("B4") Then Exit Sub
If Range("A4").Value <> Range("B4") Then
TheMacro
End If
End Sub

Sub TheMacro()
MsgBox "The cities are not the same"
End Sub

Regards,
Howard
 
Top