The following code generates an error on the InputBox command if Cancel is Clicked.
What is needed to allow the Cancel to be clicked and exit the Sub if it was clicked.
I'm checking for "False" but the program fails on the Input Command just before this check.
What is needed to allow the Cancel to be clicked and exit the Sub if it was clicked.
I'm checking for "False" but the program fails on the Input Command just before this check.
Code:
Sub NameSelectedCells()
Dim vInputCells, vRefersto_Cell_Range As Range
'type:=8 for cell references or ranges; change the Left and Top arguments to position the InputBox
Set vInputCells = Application.InputBox(prompt:="Select cells to be named...", Left:=1, Top:=1, Type:=8)
If vInputCells = False Then Exit Sub
vSheet_Range = "'" & ActiveSheet.Name & "'!" & vInputCells.Address(ReferenceStyle:=xlA1)
Set vRefersto_Cell_Range = Range(vSheet_Range)
Do
vRangeName = InputBox("Assign the Range[" & vSheet_Range & "]" & vbCr & _
"to the following Name...")
If vRangeName = "" Then Exit Sub
On Error Resume Next
Names.Add Name:=vRangeName, RefersTo:=vRefersto_Cell_Range, Visible:=True
If Err.Number = 0 Then Exit Sub
MsgBox "RangeName... [" & vRangeName & "] is Invalid!" & vbCr & _
"Must Not start with a Number, Must Not contain a Space, Only underscore (_) special character is allowed"
Loop
End Sub