View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.misc
puiuluipui puiuluipui is offline
external usenet poster
 
Posts: 468
Default Run macro only if

Hi, this is almost what i need. But if i have three macro at the end of your
macro, it's not running the first or the second macro but the third.
Can't this macro have my code in the middle of yours?
Ex:
Sub Macro1()
Set sht = Sheets("Sheet1") ' change to suit
With sht
If UCase(.Range("A1")) = "JOHN" _
And UCase(.Range("C1")) = "MARI" _
And .Range("D1") = "" Then
msg = MsgBox("Macro 1", vbInformation, "Running")

'my macro 1
Range("A1:C15").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Range("A1").Select
'end of my macro 1

ElseIf UCase(.Range("A1")) = "JIM" _
And UCase(.Range("C1")) = "CRIS" _
And UCase(.Range("D1")) = "MONDAY" Then
msg = MsgBox("Macro 2", vbInformation, "Running")
Macro2
Else
MsgBox "Criteria not met"
Exit Sub
End If

'my macro 2
Range("A1:C15").Select
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
Range("A1").Select
End With
'end of my macro 2

End Sub

Can this be done to avoid the third macro?
Thanks!

"Per Jessen" a scris:

Hi

This should do it:

Sub Macro1()
Set sht = Sheets("Sheet1") ' change to suit
With sht
If UCase(.Range("A1")) = "JOHN" _
And UCase(.Range("C1")) = "MARI" _
And .Range("D1") = "" Then
msg = MsgBox("Macro 1", vbInformation, "Running")
ElseIf UCase(.Range("A1")) = "JIM" _
And UCase(.Range("C1")) = "CRIS" _
And UCase(.Range("D1")) = "MONDAY" Then
msg = MsgBox("Macro 2", vbInformation, "Running")
Macro2
Else
MsgBox "Criteria not met"
Exit Sub
End If
End With
'Your code

End Sub

"puiuluipui" skrev i meddelelsen
...
Hi, it's perfect!
But i have one more question. Can this macro be made to run another macro
if
in A1 and C1 is another names?

EX:
A1 = John
C1 = Mari
D1 = "empty"
If this criteria is met, then the macro to run MACRO 1
If in this cells i have:
A1 = Jim
C1 = Cris
D1 = Monday
and the macro to run MACRO 2.
and if it's possible, the message box, to display the name of the macro
that
it's running (MACRO 1 or MACRO 2)

Can this be done?
Thanks!!!



"Mike H" a scris:

Hi,

Is this what you mean

Sub somemacro()
Set sht = Sheets("Sheet1") ' change to suit
With sht
If UCase(.Range("A1")) < "JOHN" _
Or UCase(.Range("C1")) < "MARI" _
Or .Range("D1") < "" Then
MsgBox "Criteria not met"
Exit Sub
End If
End With
'Your code

End Sub

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"puiuluipui" wrote:

Hi, i need a macro to run if A1 contains "John" and C1 contains "Mari",
and
if D1 is blank. If this criteria is not mached, then the macro to
display a
message.
Can this be done?
Thanks!


.