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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Paddy1979

Well-known Member
Joined
Sep 23, 2005
Messages
608
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

donalde

Board Regular
Joined
Feb 27, 2002
Messages
80
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

Lewiy

Well-known Member
Joined
Jan 5, 2007
Messages
4,284
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

Paddy1979

Well-known Member
Joined
Sep 23, 2005
Messages
608
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

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
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,191,708
Messages
5,988,232
Members
440,139
Latest member
ngaicuong2017

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
Top