![]() |
If then - do while - vlookup combo
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 |
If then - do while - vlookup combo
Accidentally put this in the wrong section. It's meant for excel. Sorry!
"csjames" wrote: 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 |
All times are GMT +1. The time now is 08:42 PM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com