![]() |
Write a branch to another macro
I want to write an IF statement in VBA whe if cell B7=1 then run macro
Ctrl+a if cell B7=2 run macro Ctrl+b otherwise return a message "Incorrect entry". |
Write a branch to another macro
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 On Apr 9, 8:01*pm, iashorty wrote: I want to write an IF statement in VBA whe if cell B7=1 then run macro Ctrl+a if cell B7=2 run macro Ctrl+b otherwise return a message "Incorrect entry". |
Write a branch to another macro
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. iashorty wrote: I want to write an IF statement in VBA whe if cell B7=1 then run macro Ctrl+a if cell B7=2 run macro Ctrl+b otherwise return a message "Incorrect entry". -- Dave Peterson |
Write a branch to another macro
change that second "case is = 1" to "case is = 2".
Dave Peterson wrote: 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. iashorty wrote: I want to write an IF statement in VBA whe if cell B7=1 then run macro Ctrl+a if cell B7=2 run macro Ctrl+b otherwise return a message "Incorrect entry". -- Dave Peterson -- Dave Peterson |
Write a branch to another macro
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 "iashorty" wrote: I want to write an IF statement in VBA whe if cell B7=1 then run macro Ctrl+a if cell B7=2 run macro Ctrl+b otherwise return a message "Incorrect entry". |
Write a branch to another macro
Thank you everyone. You are all very helpful.
IAShorty "iashorty" wrote: I want to write an IF statement in VBA whe if cell B7=1 then run macro Ctrl+a if cell B7=2 run macro Ctrl+b otherwise return a message "Incorrect entry". |
All times are GMT +1. The time now is 02:23 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com