or another way to capture the error if canel button is clicked
Option Explicit
Sub Input_Value()
Dim LocationCode
Dim IsValid As Boolean
Do Until IsValid
'Ask the user to input Location code into inout box
LocationCode = InputBox("Enter a Location Code 1 or 2", "Location Code", 1)
' Cofirms that the user entered a 1 or 2
Select Case LocationCode
Case ""
MsgBox "You have cancelled"
Exit Sub
Case 1, 2
MsgBox "You did enter a 1 or 2"
IsValid = True
Case Else
MsgBox "Sorry you did not enter a 1 or 2. Please try again."
End Select
Loop
MsgBox " You Have exited the Loop"
' Your next code
End Sub