G
Guest
Here is the code that I currently have. It works as long as the user either
leaves it blank or enters a correct number. However, I can't figure out how
to insert an if then for when the user enters a wrong number without it
having an error. Any help is appreciated.
Option Explicit
Sub GetAnswer()
' Created by CJ
'Enter an abbreviation and this will tell you which branch it is for.
Dim Num As Variant
Dim Answer As Variant
Dim msg As String
Dim Ans As Variant
Dim Nums As Variant
'Prompt for a value
Do
Num = InputBox("What is the branch number you would like to look up?")
'Exit if cancelled
If Num = "" Then Exit Sub
'Look up the abbreviation and return an answer.
Answer = Application.VLookup(CLng(Num), Range("BranchNumbers"), 4, False)
'Show which branch the number goes to
MsgBox Num & " is the Branch " & Answer & "."
'Ask if they would like to look up another number
msg = MsgBox("Would you like to look up another branch?", vbYesNo)
Loop While msg = vbYes
End Sub
Thanks
CJ
leaves it blank or enters a correct number. However, I can't figure out how
to insert an if then for when the user enters a wrong number without it
having an error. Any help is appreciated.
Option Explicit
Sub GetAnswer()
' Created by CJ
'Enter an abbreviation and this will tell you which branch it is for.
Dim Num As Variant
Dim Answer As Variant
Dim msg As String
Dim Ans As Variant
Dim Nums As Variant
'Prompt for a value
Do
Num = InputBox("What is the branch number you would like to look up?")
'Exit if cancelled
If Num = "" Then Exit Sub
'Look up the abbreviation and return an answer.
Answer = Application.VLookup(CLng(Num), Range("BranchNumbers"), 4, False)
'Show which branch the number goes to
MsgBox Num & " is the Branch " & Answer & "."
'Ask if they would like to look up another number
msg = MsgBox("Would you like to look up another branch?", vbYesNo)
Loop While msg = vbYes
End Sub
Thanks
CJ