Close input box

annadinesh

Board Regular
Joined
Mar 1, 2017
Messages
128
Office Version
  1. 2019
Platform
  1. Windows
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

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
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,224,881
Messages
6,181,536
Members
453,054
Latest member
ezzat

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