Input box VBOKCancel problem

Jmoz092

Board Regular
Joined
Sep 8, 2017
Messages
184
Office Version
  1. 365
  2. 2011
Platform
  1. Windows
  2. MacOS
I'm having an issue with an application.inputbox in a macro. It keeps popping up with a "1" in the user input section when the message box initially appears. Why is this happening?

Code:
Dim BeginDate As Variant
ShowInputBox:
BeginDate = Application.InputBox("What is the first day of the next month's workbook that you wish to create?", "Workbook Begin Date mm-dd-yyy", vbOKCancel)
If BeginDate = vbCancel Then
Exit Sub
ElseIf BeginDate = "" Then
MsgBox "No Begin Date Was Entered"
Exit Sub
Else
Sheet49.Range("a2").Value = BeginDate
End If
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try:
Code:
Dim BeginDate As Variant
ShowInputBox:
BeginDate = Application.InputBox("What is the first day of the next month's workbook that you wish to create?", "Workbook Begin Date mm-dd-yyy", , vbOKCancel)
If BeginDate = vbCancel Then
Exit Sub
ElseIf BeginDate = "" Then
MsgBox "No Begin Date Was Entered"
Exit Sub
Else
Sheet49.Range("a2").Value = BeginDate
End If
You left out a comma to the left of vbOKCancel. The Cancel button will appear but it won't work as expected.
 
Last edited:
Upvote 0
I'm having an issue with an application.inputbox in a macro. It keeps popping up with a "1" in the user input section when the message box initially appears. Why is this happening?

Code:
Dim BeginDate As Variant
ShowInputBox:
BeginDate = Application.InputBox("What is the first day of the next month's workbook that you wish to create?", "Workbook Begin Date mm-dd-yyy", vbOKCancel)
If BeginDate = vbCancel Then
Exit Sub
ElseIf BeginDate = "" Then
MsgBox "No Begin Date Was Entered"
Exit Sub
Else
Sheet49.Range("a2").Value = BeginDate
End If
The 1 is coming from vbOkCancel as that is the underlying value for that built-in VB constant. The reason it is appearing in the user's input section is because you put it in the argument position for the InputBox's Default value. The problem is that you are trying to use a MessagBox argument in an InputBox... the Application.InputBox always displays an OK and a Cancel button and has no provision that I am aware of to change the buttons that appear. To solve your problem, simply remove that last argument (and the comma in front of it).
 
Upvote 0
Took out the last part and comma as educated. Thanks, as always, for explaining why the issue was occurring, and thanks for the reference link!
 
Upvote 0
You are welcome. Glad we could help!:)
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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