questions with yes no and cancel

MAMIBUSSOL

Board Regular
Joined
Jun 2, 2011
Messages
95
I need to do the following task with variables

I ask the question?

"DO YOU HAVE ANY ASSETS"

the response will be either

NO - in which case I carry on with my coding

CANCEL - exits script completely

YES - request user to enter name of asset; recorded into a variable
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Maybe like this

Code:
ans = MsgBox("DO YOU HAVE ANY ASSETS", vbYesNoCancel + vbQuestion)
If ans = vbCancel Then
    Exit Sub
ElseIf ans = vbYes Then
    asset = InputBox("Enter name of asset")
End If
 
Upvote 0
Hello,

What if the cancel is choosen while whithin the input box?


<font face=Courier New><SPAN style="color:#00007F">Dim</SPAN> Ans<br>Ans = MsgBox("DO YOU HAVE ANY ASSETS", vbYesNoCancel, "Assets?")<br><br><SPAN style="color:#00007F">If</SPAN> Ans = vbCancel <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><SPAN style="color:#00007F">If</SPAN> Ans = vbYes <SPAN style="color:#00007F">Then</SPAN> Ans = InputBox("Request user to enter name of asset.", "Asset")<br><SPAN style="color:#00007F">If</SPAN> Ans = "" <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
if I have various assets and values to add, how could I adjust to repeat until the user tells me they have all been added
 
Upvote 0
Perhaps something like

Code:
Dim uiAsset As String

Do
    uiAsset = Application.InputBox("Enter the new asset", Default:="[No More Assets]", Type:=2)
    If uiAsset = "False" Then Exit Sub: Rem cancel
    If uiAsset <> "[No More Assets]" Then
        Rem process new asset
    End If
Loop Until uiAsset = "[No More Assets]"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,786
Members
452,942
Latest member
VijayNewtoExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top