GoTo a different Sub

  • Thread starter Thread starter Greenhorn
  • Start date Start date
G

Greenhorn

This is gotta be basic and it did work when I first ran
it. But does not today.
I just want it to go to a different sub dependant on the
answer.


Thanks,
------------------------------

Sub Sub1()

Range("i23").Select
Answer = MsgBox("Yes or No?", vbYesNo, "Answer")
If Answer = vbYes Then
ActiveCell.Value = "Y"
Range("i23").Select
Else
ActiveCell.Value = "N"
Range("i23").Select
End If

If Answer = vbYes Then
Application.Goto: Sub2
Else
Application.Goto: Sub3

End If

End Sub
 
is Sub2 and sub3 goto lables within Sub1 or are the seperate macros

Exaples supplied of going sub & calling another macro



Sub Sub1()

Range("i23").Select
Answer = MsgBox("Yes or No?", vbYesNo, "Answer")
If Answer = vbYes Then
ActiveCell.Value = "Y"
goto sub2
Else
ActiveCell.Value = "N"
goto sub3
End If
exit sub
sub2:
do something
exit sub or return
sub3:
do something
exit sub or return
End Sub

=================================
Sub Sub1()

Range("i23").Select
Answer = MsgBox("Yes or No?", vbYesNo, "Answer")
If Answer = vbYes Then
ActiveCell.Value = "Y"
call sub2
Else
ActiveCell.Value = "N"
call sub3

End If

End Sub

sub Sub2
do something
end sub

sub3
do something
end sub
 
I think you want to do it this way (To run another subroutine in the same
workbook, just list its name on its own line)

Bob Flanagan
Macro Systems
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel


Sub1()
Range("i23").Select
Answer = MsgBox("Yes or No?", vbYesNo, "Answer")
If Answer = vbYes Then
ActiveCell.Value = "Y"
Sub2
Else
ActiveCell.Value = "N"
Sub3
End If
End Sub

Sub Sub2()
'some code
End sub

Sub Sug3()
'some code
end sub
 
The call routine worked like a charm... and easy. I guess
I was over-analyzing it.

Thank you both!

GH
 

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