Close input box

annadinesh

Board Regular
Joined
Mar 1, 2017
Messages
105
Dear Experts

I am using this formula and it was working fine.

Dim FindString As String
Dim rng As Range

BackInp:
FindString = InputBox("Enter VIN Number to Search")
If Len(FindString) < 17 Then
MsgBox "VIN Number must be 17 Charachter"
GoTo BackInp
end if

but input box was not close on pressing Cancel or cross button

i want that if i press cancel button on input box it should close


Please advice



Regards

Dinesh
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
That's because you have a permanent 'loop' with this line:
VBA Code:
GoTo BackInp
which means you will always go back to this line:
VBA Code:
BackInp:
unless the input is exactly 17 characters long.
Advice: remove the GoTo line
 
Upvote 0
You can test for nothing being entered separately - for example:

VBA Code:
Dim FindString As String
Dim rng As Range

BackInp:
FindString = InputBox("Enter VIN Number to Search")
If Len(FindString) = 0 Then
   Exit Sub
ElseIf Len(FindString) < 17 Then
MsgBox "VIN Number must be 17 characters"
GoTo BackInp
End If
 
Upvote 0
Solution
You can test for nothing being entered separately - for example:

VBA Code:
Dim FindString As String
Dim rng As Range

BackInp:
FindString = InputBox("Enter VIN Number to Search")
If Len(FindString) = 0 Then
   Exit Sub
ElseIf Len(FindString) < 17 Then
MsgBox "VIN Number must be 17 characters"
GoTo BackInp
End If
WORKS, THANKS
 
Upvote 0

Forum statistics

Threads
1,215,076
Messages
6,122,984
Members
449,092
Latest member
Mr Hughes

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