# Input Box

##### Well-known Member
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

#### Lewiy

##### Well-known Member
Have you tried:
If dnumber = "" Then Exit Sub

#### Richard Schollar

##### MrExcel MVP
What do you hve dnumber declared as? It needs to be a variant.

#### al_b_cnu

##### Well-known Member
Hi,

Have you dimmed dNumber as a Variant?

##### Well-known Member
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???

#### donalde

##### Board Regular
Hi

Inputbox returns string. And if Cancel is pressed, it returns zero lenght string. So, you need to have If dnumber = "" Then Exit Sub

#### Lewiy

##### Well-known Member
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.

##### Well-known Member
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.

#### Richard Schollar

##### MrExcel MVP
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.

Right, got ya.

Thanks Richard

Replies
3
Views
223
Replies
1
Views
310
Replies
7
Views
483
Replies
2
Views
345
Replies
11
Views
424

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.

### Which adblocker are you using?

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

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