Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 394
Default MsgBox with Two Questions

Hi everybody,

I have the code ...

Private Sub Test()

Dim Question1 As Variant
Dim Question2 As Variant

Question1 = MsgBox( _
"Text." & vbNewLine & _
Worksheets("W").Range("B3").Value & vbNewLine _
& vbNewLine & _
"Click YES if either of the following are TRUE :- " & vbNewLine & _
"(1) Text." & vbNewLine & _
"(2) Text." & vbNewLine & _
" (Text)" & vbNewLine _
& vbNewLine & _
"Click NO if either of the following are TRUE :-" & vbNewLine & _
"(1) Text." & vbNewLine & _
"(2) Text.", vbYesNo, "Title")
If Question1 < vbYes Then
Application.Goto Reference:=Sheets("W").Range("B3")
Exit Sub
End If

Question2 = MsgBox( _
"Text." & vbNewLine _
& vbNewLine & _
"Text." & vbNewLine & _
"Text.", vbYesNo, "Title")
If Question2 < vbYes Then
Application.Goto Reference:=Sheets("W").Range("B5")
Exit Sub
End If
End Sub

.... which unfortunately does NOT goto the correct cell if the answer
is NO, it exits the "Test" Sub but still runs the "Main" Sub instead
of exiting the "Main" Sub.
I call the "Test" Sub above from the beginning of the "Main" Sub.
It appears to exit the "Test" Sub but it does NOT exit the "Main"
Sub.
Any ideas will be greatly appreciated.

Thanks in Advance.
All the Best.
Paul

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default MsgBox with Two Questions

So you're calling Test from Main?

If yes, then maybe you can turn Test into a function so that it returns some
sort of indicator so that Main knows what happened the

Option Explicit
Sub Main()

dim Resp as string 'matches what Test returns
resp = Test

if resp = "VbNo to question1" then
'do what you want
else
'do something else
end if
end sub

Private Function Test() As String

Dim Question1 As Variant
Dim Question2 As Variant
Dim myStr As String

myStr = ""
Question1 = MsgBox( _
"Text." & vbNewLine & _
Worksheets("W").Range("B3").Value & vbNewLine _
& vbNewLine & _
"Click YES if either of the following are TRUE :- " & vbNewLine
& _
"(1) Text." & vbNewLine & _
"(2) Text." & vbNewLine & _
" (Text)" & vbNewLine _
& vbNewLine & _
"Click NO if either of the following are TRUE :-" & vbNewLine &
_
"(1) Text." & vbNewLine & _
"(2) Text.", vbYesNo, "Title")
If Question1 < vbYes Then
Application.Goto Reference:=Sheets("W").Range("B3")
myStr = "VbNo to question1"
Test = myStr
Exit Function
End If

Question2 = MsgBox( _
"Text." & vbNewLine _
& vbNewLine & _
"Text." & vbNewLine & _
"Text.", vbYesNo, "Title")
If Question2 < vbYes Then
Application.Goto Reference:=Sheets("W").Range("B5")
Exit Function
End If
End Function

Paul Black wrote:

Hi everybody,

I have the code ...

Private Sub Test()

Dim Question1 As Variant
Dim Question2 As Variant

Question1 = MsgBox( _
"Text." & vbNewLine & _
Worksheets("W").Range("B3").Value & vbNewLine _
& vbNewLine & _
"Click YES if either of the following are TRUE :- " & vbNewLine & _
"(1) Text." & vbNewLine & _
"(2) Text." & vbNewLine & _
" (Text)" & vbNewLine _
& vbNewLine & _
"Click NO if either of the following are TRUE :-" & vbNewLine & _
"(1) Text." & vbNewLine & _
"(2) Text.", vbYesNo, "Title")
If Question1 < vbYes Then
Application.Goto Reference:=Sheets("W").Range("B3")
Exit Sub
End If

Question2 = MsgBox( _
"Text." & vbNewLine _
& vbNewLine & _
"Text." & vbNewLine & _
"Text.", vbYesNo, "Title")
If Question2 < vbYes Then
Application.Goto Reference:=Sheets("W").Range("B5")
Exit Sub
End If
End Sub

... which unfortunately does NOT goto the correct cell if the answer
is NO, it exits the "Test" Sub but still runs the "Main" Sub instead
of exiting the "Main" Sub.
I call the "Test" Sub above from the beginning of the "Main" Sub.
It appears to exit the "Test" Sub but it does NOT exit the "Main"
Sub.
Any ideas will be greatly appreciated.

Thanks in Advance.
All the Best.
Paul


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 394
Default MsgBox with Two Questions

Thanks for the reply Dave,

If yes, then maybe you can turn "Test" into a Function so that it returns some
sort of indicator so that "Main" Sub knows what happened there.


You are quite right, the answer is "Yes".

The "Main" Sub works great. What I am trying to achieve is that two
questions need to be answered, and depending on those answers then
some action is taken.

If the answer to Question1 is "Yes" Then
Ask Question2
Else
If the answer to Question1 is "No" Then
Goto Sheet("W").Range("B3") and Exit the "Test" Sub or Function

If the answer to Question2 is "No" Then
Goto Sheet("W").Range("B5") and Exit the "Test" Sub or Function
Else
If the answer to Question2 is "Yes" Then
Continue to run the "test" Sub or Function

Thanks in Advance.
All the Best.
Paul

On Sep 15, 10:11 pm, Dave Peterson wrote:
So you're calling Test from Main?

If yes, then maybe you can turn Test into a function so that it returns some
sort of indicator so that Main knows what happened the

Option Explicit
Sub Main()

dim Resp as string 'matches what Test returns
resp = Test

if resp = "VbNo to question1" then
'do what you want
else
'do something else
end if
end sub

Private Function Test() As String

Dim Question1 As Variant
Dim Question2 As Variant
Dim myStr As String

myStr = ""
Question1 = MsgBox( _
"Text." & vbNewLine & _
Worksheets("W").Range("B3").Value & vbNewLine _
& vbNewLine & _
"Click YES if either of the following are TRUE :- " & vbNewLine
& _
"(1) Text." & vbNewLine & _
"(2) Text." & vbNewLine & _
" (Text)" & vbNewLine _
& vbNewLine & _
"Click NO if either of the following are TRUE :-" & vbNewLine &
_
"(1) Text." & vbNewLine & _
"(2) Text.", vbYesNo, "Title")
If Question1 < vbYes Then
Application.Goto Reference:=Sheets("W").Range("B3")
myStr = "VbNo to question1"
Test = myStr
Exit Function
End If

Question2 = MsgBox( _
"Text." & vbNewLine _
& vbNewLine & _
"Text." & vbNewLine & _
"Text.", vbYesNo, "Title")
If Question2 < vbYes Then
Application.Goto Reference:=Sheets("W").Range("B5")
Exit Function
End If
End Function





Paul Black wrote:

Hi everybody,


I have the code ...


Private Sub Test()


Dim Question1 As Variant
Dim Question2 As Variant


Question1 = MsgBox( _
"Text." & vbNewLine & _
Worksheets("W").Range("B3").Value & vbNewLine _
& vbNewLine & _
"Click YES if either of the following are TRUE :- " & vbNewLine & _
"(1) Text." & vbNewLine & _
"(2) Text." & vbNewLine & _
" (Text)" & vbNewLine _
& vbNewLine & _
"Click NO if either of the following are TRUE :-" & vbNewLine & _
"(1) Text." & vbNewLine & _
"(2) Text.", vbYesNo, "Title")
If Question1 < vbYes Then
Application.Goto Reference:=Sheets("W").Range("B3")
Exit Sub
End If


Question2 = MsgBox( _
"Text." & vbNewLine _
& vbNewLine & _
"Text." & vbNewLine & _
"Text.", vbYesNo, "Title")
If Question2 < vbYes Then
Application.Goto Reference:=Sheets("W").Range("B5")
Exit Sub
End If
End Sub


... which unfortunately does NOT goto the correct cell if the answer
is NO, it exits the "Test" Sub but still runs the "Main" Sub instead
of exiting the "Main" Sub.
I call the "Test" Sub above from the beginning of the "Main" Sub.
It appears to exit the "Test" Sub but it does NOT exit the "Main"
Sub.
Any ideas will be greatly appreciated.


Thanks in Advance.
All the Best.
Paul


--

Dave Peterson- Hide quoted text -

- Show quoted text -



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default MsgBox with Two Questions

I don't understand.

If two questions must be answered, then if the user answers yes to Q1, then you
exit that function/sub. So two questions aren't asked/answered.



Paul Black wrote:

Thanks for the reply Dave,

If yes, then maybe you can turn "Test" into a Function so that it returns some
sort of indicator so that "Main" Sub knows what happened there.


You are quite right, the answer is "Yes".

The "Main" Sub works great. What I am trying to achieve is that two
questions need to be answered, and depending on those answers then
some action is taken.

If the answer to Question1 is "Yes" Then
Ask Question2
Else
If the answer to Question1 is "No" Then
Goto Sheet("W").Range("B3") and Exit the "Test" Sub or Function

If the answer to Question2 is "No" Then
Goto Sheet("W").Range("B5") and Exit the "Test" Sub or Function
Else
If the answer to Question2 is "Yes" Then
Continue to run the "test" Sub or Function

Thanks in Advance.
All the Best.
Paul

On Sep 15, 10:11 pm, Dave Peterson wrote:
So you're calling Test from Main?

If yes, then maybe you can turn Test into a function so that it returns some
sort of indicator so that Main knows what happened the

Option Explicit
Sub Main()

dim Resp as string 'matches what Test returns
resp = Test

if resp = "VbNo to question1" then
'do what you want
else
'do something else
end if
end sub

Private Function Test() As String

Dim Question1 As Variant
Dim Question2 As Variant
Dim myStr As String

myStr = ""
Question1 = MsgBox( _
"Text." & vbNewLine & _
Worksheets("W").Range("B3").Value & vbNewLine _
& vbNewLine & _
"Click YES if either of the following are TRUE :- " & vbNewLine
& _
"(1) Text." & vbNewLine & _
"(2) Text." & vbNewLine & _
" (Text)" & vbNewLine _
& vbNewLine & _
"Click NO if either of the following are TRUE :-" & vbNewLine &
_
"(1) Text." & vbNewLine & _
"(2) Text.", vbYesNo, "Title")
If Question1 < vbYes Then
Application.Goto Reference:=Sheets("W").Range("B3")
myStr = "VbNo to question1"
Test = myStr
Exit Function
End If

Question2 = MsgBox( _
"Text." & vbNewLine _
& vbNewLine & _
"Text." & vbNewLine & _
"Text.", vbYesNo, "Title")
If Question2 < vbYes Then
Application.Goto Reference:=Sheets("W").Range("B5")
Exit Function
End If
End Function





Paul Black wrote:

Hi everybody,


I have the code ...


Private Sub Test()


Dim Question1 As Variant
Dim Question2 As Variant


Question1 = MsgBox( _
"Text." & vbNewLine & _
Worksheets("W").Range("B3").Value & vbNewLine _
& vbNewLine & _
"Click YES if either of the following are TRUE :- " & vbNewLine & _
"(1) Text." & vbNewLine & _
"(2) Text." & vbNewLine & _
" (Text)" & vbNewLine _
& vbNewLine & _
"Click NO if either of the following are TRUE :-" & vbNewLine & _
"(1) Text." & vbNewLine & _
"(2) Text.", vbYesNo, "Title")
If Question1 < vbYes Then
Application.Goto Reference:=Sheets("W").Range("B3")
Exit Sub
End If


Question2 = MsgBox( _
"Text." & vbNewLine _
& vbNewLine & _
"Text." & vbNewLine & _
"Text.", vbYesNo, "Title")
If Question2 < vbYes Then
Application.Goto Reference:=Sheets("W").Range("B5")
Exit Sub
End If
End Sub


... which unfortunately does NOT goto the correct cell if the answer
is NO, it exits the "Test" Sub but still runs the "Main" Sub instead
of exiting the "Main" Sub.
I call the "Test" Sub above from the beginning of the "Main" Sub.
It appears to exit the "Test" Sub but it does NOT exit the "Main"
Sub.
Any ideas will be greatly appreciated.


Thanks in Advance.
All the Best.
Paul


--

Dave Peterson- Hide quoted text -

- Show quoted text -


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
More MsgBox questions. Pete[_6_] Excel Discussion (Misc queries) 2 December 21st 09 09:24 PM
Answers to questions posing more questions in a workbook sbelle1 Excel Worksheet Functions 2 August 8th 09 01:02 AM
View Questions and Answer to questions I created Roibn Taylor Excel Discussion (Misc queries) 4 July 24th 08 12:05 AM
msgbox (2 questions) Yan Robidoux[_13_] Excel Programming 4 September 3rd 04 02:29 PM
Can MsgBox Do This?? foamfollower Excel Programming 4 January 20th 04 12:09 AM


All times are GMT +1. The time now is 01:09 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"