A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

If then - do while - vlookup combo



 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2  
Old June 28th 07, 11:18 PM posted to microsoft.public.outlook.program_vba
csjames
external usenet poster
 
Posts: 2
Default 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

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Combo box skar3000 Outlook - Using Forms 3 June 15th 07 02:14 PM
Adding calender in a combo box Mark the Outlook Idiot Outlook - Using Forms 2 February 7th 07 07:26 PM
Combo Box values resetting [email protected] Outlook - Using Forms 2 October 31st 06 05:01 PM
Populate a combo box Steffkm Outlook - Using Forms 4 March 14th 06 09:28 PM
Dropdown controls - List vs Combo Don Smith Outlook - Using Forms 2 January 20th 06 07:46 PM


All times are GMT +1. The time now is 08:55 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-2025 Outlook Banter.
The comments are property of their posters.