Input Box

Paddy1979

Well-known Member
Joined
Sep 23, 2005
Messages
608
Hi people , banging my head against the wall , got this small problem i cant solve,

The input box is for Period Number Entry,

However if the user enters the period number as 'P6' with the prefix 'P' as required, it bugging out on line

If dnumber = False Then Exit Sub

Any ideas? , cheers all.

Code:
here:
dnumber = Application.InputBox("Please input the Period number the INNS023 data reflects", "Period Number", "")

If dnumber = False Then Exit Sub

If Left(dnumber, 1) <> "P" Then
 MsgBox " With Prefix 'P'"
 GoTo here:
End If

'do x y z
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi chaps

It is declared as String Richard,

If If dnumber = "" Then Exit Sub , if cancelled is clicked it retuend to here: Lewiy

any thoughts???
 
Upvote 0
Hi

Inputbox returns string. And if Cancel is pressed, it returns zero lenght string. So, you need to have If dnumber = "" Then Exit Sub
 
Upvote 0
If you click cancel on an input box, it returns a blank, i.e:
Code:
Dim i as string
i = InputBox("Enter something here")
MsgBox i

Try that code and click cancel and the message box will be blank.
 
Upvote 0
Ah Changed dnumber to variant and its now working.

God i have justed wasted an hour of my life trying to sort that little bugger out.

Cheers all for your help
 
Upvote 0
The Inputbox method returns a boolean if Cancel is pressed, hence why you need the variable holder declared as a variant (so it can hold booleans in addition to strings). The inputbox function will return an empty string if Cancel is applied.
 
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,185
Members
448,554
Latest member
Gleisner2

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