Macro if criteria

  • Follow


Hi, i have two macros. (macro 1 and macro 2)
I need macro 1 to run if in A1 is "JOHN", in B1 is "MARY" and if C1 is empty 
; and macro 2 to run if in A1 is "JIM", in B1 is "CRIS" and in C1 is "BOB".
Can this be done?
Thanks!
0
Reply Utf 6/7/2010 7:47:33 PM

Seems simple

    If Range("A1").Value2 = "JOHN" And _
       Range("B1").Value2 = "MARY" And _
       Range("C1").Value2 = "" Then
        Call Macro1
    ElseRange("A1").Value2 = "JIM" And _
       Range("B1").Value2 = "CRIS" And _
       Range("C1").Value2 = "BOB" Then
        Call Macro2
    End If

-- 

HTH

Bob

"puiuluipui" <puiuluipui@discussions.microsoft.com> wrote in message 
news:16274013-FE47-480E-93F6-C126676223C6@microsoft.com...
> Hi, i have two macros. (macro 1 and macro 2)
> I need macro 1 to run if in A1 is "JOHN", in B1 is "MARY" and if C1 is 
> empty
> ; and macro 2 to run if in A1 is "JIM", in B1 is "CRIS" and in C1 is 
> "BOB".
> Can this be done?
> Thanks! 


0
Reply Bob 6/7/2010 8:33:03 PM


Put this behind your sheet:
Private Sub Worksheet_Change(ByVal Target As Range)
    'If Target.Cells.Count > 3 Then Exit Sub
    If Application.Intersect(Range("A1"), Target) Is Nothing Then
        If Not IsNumeric(Target.Value) And Range("A1").Value = "JIM" And 
Range("B1").Value = "CHRIS" And Range("C1").Value = "BOB" Then
        Call Macro2
        End If
        
            If Not IsNumeric(Target.Value) And Range("A1").Value = "JOHN" 
And Range("B1").Value = "MARY" And Range("C1").Value = "" Then
                Call Macro1
            End If

    End If
End Sub


Put this in a Module:
Sub Macro1()
'Display MessageBox
    Answer = MsgBox("Macro1")

End Sub

Sub Macro2()
'Display MessageBox
    Answer = MsgBox("Macro2")

End Sub



-- 
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"puiuluipui" wrote:

> Hi, i have two macros. (macro 1 and macro 2)
> I need macro 1 to run if in A1 is "JOHN", in B1 is "MARY" and if C1 is empty 
> ; and macro 2 to run if in A1 is "JIM", in B1 is "CRIS" and in C1 is "BOB".
> Can this be done?
> Thanks!
0
Reply Utf 6/7/2010 8:53:09 PM

2 Replies
485 Views

(page loaded in 1.984 seconds)


Reply: