Input box VBOKCancel problem

Jmoz092

Board Regular
Joined
Sep 8, 2017
Messages
182
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 change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
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,215,006
Messages
6,122,665
Members
449,091
Latest member
peppernaut

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