Write a branch to another macro

  • Thread starter Thread starter iashorty
  • Start date Start date
I

iashorty

I want to write an IF statement in VBA where: if cell B7=1 then run macro
Ctrl+a if cell B7=2 run macro Ctrl+b otherwise return a message "Incorrect
entry".
 
Sub MyMacro()

If Worksheets("mysheet").Range("B7").Value = 1 Then
Call Macro1
ElseIf Worksheets("mysheet").Range("B7").Value = 2 Then
Call Macro2
Else MsgBox "Incorrect Entry"
End If

End Sub


HTH,
JP
 
Select case worksheets("sheet1").range("b7").value
case is = 1
call NameOfMacroA
case is = 1
call NameOfMacroB
case else
msgbox "incorrect entry"
end select

Use the name of the macro--not the shortcut key.
 
hi
if Range("B7").value = 1 then
Call macro1
else
if range("B7")= 2 then
Call Macro2
else
msgbox "Incorrect entry"
exit sub
end if
end if

regards
FSt1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top