ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Branching Macro (https://www.excelbanter.com/excel-programming/281692-branching-macro.html)

Paul Moles[_2_]

Branching Macro
 
I am trying to get a macro to “branch” based
upon the
value in a given cell of the worksheet.

Basically if the cell value is zero then the macro should
stop and inform the user with a message box. So the error
can be corrected.

If the cell value is above zero then a longer much more
complete macro should run.(Called Copy_Across which for
simplicity I have paraphrased here)

Any help appreciated.
Paul

Sub Check_Macro()
'
'Check to see closing stock has been entered

If (L53 < 1) Then GoSub Stock_Entry
If (L53 1) Then GoSub Copy_Across
End Sub

Sub Stock_Entry()

MsgBox "No Closing Stock Entered Sunday"
End Sub

Sub Copy_Across()

Application.Goto Reference:="Date_Sheet2"
MsgBox "Ok This Time"

End Sub


Dianne

Branching Macro
 
Sub Check_Macro()
Select Case Range("L53").Value
Case Is < 1: Call Stock_Entry
Case Is = 1: Call Copy_Across
End Select
End Sub

--
Dianne

In ,
Paul Moles typed:
I am trying to get a macro to “branch” based
upon the
value in a given cell of the worksheet.

Basically if the cell value is zero then the macro should
stop and inform the user with a message box. So the error
can be corrected.

If the cell value is above zero then a longer much more
complete macro should run.(Called Copy_Across which for
simplicity I have paraphrased here)

Any help appreciated.
Paul

Sub Check_Macro()
'
'Check to see closing stock has been entered

If (L53 < 1) Then GoSub Stock_Entry
If (L53 1) Then GoSub Copy_Across
End Sub

Sub Stock_Entry()

MsgBox "No Closing Stock Entered Sunday"
End Sub

Sub Copy_Across()

Application.Goto Reference:="Date_Sheet2"
MsgBox "Ok This Time"

End Sub




John Wilson

Branching Macro
 
Paul,

Try something like this:

Sub TestMe()
If Worksheets("Sheet1").Range("A1").Value = 0 Then
MsgBox "Please enter a value in A1"
Exit Sub
End If
' continue the rest of your macro here
If Range("L53") 1 Then TestMe2
If Range("L53") < 1 Then TestMe3
End Sub

Sub TestMe2()
MsgBox "TestMe2 Sub"
End Sub

Sub TestMe3()
MsgBox "TestMe3 Sub"
End Sub

John

Paul Moles wrote:

I am trying to get a macro to “branch” based
upon the
value in a given cell of the worksheet.

Basically if the cell value is zero then the macro should
stop and inform the user with a message box. So the error
can be corrected.

If the cell value is above zero then a longer much more
complete macro should run.(Called Copy_Across which for
simplicity I have paraphrased here)

Any help appreciated.
Paul

Sub Check_Macro()
'
'Check to see closing stock has been entered

If (L53 < 1) Then GoSub Stock_Entry
If (L53 1) Then GoSub Copy_Across
End Sub

Sub Stock_Entry()

MsgBox "No Closing Stock Entered Sunday"
End Sub

Sub Copy_Across()

Application.Goto Reference:="Date_Sheet2"
MsgBox "Ok This Time"

End Sub




All times are GMT +1. The time now is 05:37 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com