Message Box warning VBA

Mr2017

Well-known Member
Joined
Nov 28, 2016
Messages
644
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi

I haven't done this in a while, so would appreciate it if someone could help, please.

I'd like to create a warning when someone clicks on a button, to ask them if they have already clicked on a different button.

The buttons are 'get data' and 'analyse data'

So I'd like to create a message box that asks a user if they've clicked on the 'get data' button and if they answer 'no,' then the code exits (exit sub).

If they answer 'yes,' then the code in the 'analyse data' macro runs.

I've put this together, but need to amend it - does anyone know how?

VBA Code:
Sub Test()
    Dim Ans
    Ans = MsgBox("Have you clicked on the 'Get Data' Button", vbNo)
    If Ans = vbNo Then
        MsgBox "Click on the 'Get Data'  button"
    
    Exit Sub
        
    Else
    
    If Ans = vbYes Then
    
    'run the code that follows this comment
    
End If
    
End Sub

TIA
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I think you might need to change the Buttons argument of the MsgBox
Rich (BB code):
Ans = MsgBox("Have you clicked on the 'Get Data' Button", vbYesNo)
 
Upvote 0

Forum statistics

Threads
1,215,692
Messages
6,126,228
Members
449,303
Latest member
grantrob

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