Yes / No

Ampleford

Active Member
Joined
Mar 26, 2002
Messages
380
I'm using a dialogue box, and can't remember the code to write to stop the macro if the operator clicks no...

It looks a bit like this so far...

Sub AskFirst()
Dim msg2 As String
msg2 = "Joe Bloggs" & vbNewLine & "This is an irreversible procedure" & vbNewLine & "Are you completely sure you want to close the invoice?"
MsgBox msg2, vbYesNo, "Warning !"
End Sub


I now want it to do a number of things....

1) - If they click "No" - end sub
2) - If they click "Yes" then
a) open an input box asking for a value and placing that value on the same tab (called "close") on cell G8
b) run a macro called "Close"


who can help ? I know there's about three things in one request, but I'm really tring to push myself on these.....



thanks millions (as always)
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
1) Use an if statement, if msgbox outcome = vbNo then 'Exit Sub'
2) 'Else:' define variable & variable = input box ("Enter Value")
3) range (G8) value = range (g8) + your variable
4) 'Call' close sub routine
5) end if

hope this helps.
 
Upvote 0
I know I appear thick, but I need the actual code to write it in. When I pasted in what you had ("if msgbox outcome = vbNo then Exit Sub") then it said "Compile error - Expected: Then or Go To"

I'm not particularly good at this - I've got it to work before - but I don't have a copy of that spread to just copy and paste the code from.

Thanks

:oops:
 
Upvote 0
okay, i'm playing footy in 5 mins but if nobody else has given you the code I will do it when I get back.. Cheers.
 
Upvote 0
Now it says:- - It is cancelling OK, but won't run the macro (I'll add the inputbox later - if I can get the mechanics working now.....)

Sub AskFirst()
Dim msg2 As String
msg2 = "Joe Bloggs" & vbNewLine & "This is an irreversible procedure" & vbNewLine & "Are you completely sure you want to close the invoice?"
MsgBox msg2, vbYesNo, "Warning !"
If response = 1 Then
Application.Run "Close"
End If
End Sub


Doh !!
 
Upvote 0
You need to assign the result of the MsgBox function to a variable:

Code:
Response = MsgBox(msg2, vbYesNo, "Warning !")
If Response = vbYes Then    
   Application.Run "Close" 
End If
 
Upvote 0
The mad thing is that as I was waiting for a reply, I was working on the inputbox and sussed out that I had to do it for the input box.


Cheers


as always - my gratitude



trevor
 
Upvote 0

Forum statistics

Threads
1,221,692
Messages
6,161,336
Members
451,697
Latest member
pedroDH

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