Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default using VLOOKUP in a text box

Hello,
I have a user form with textbox1 and textbox2. I want to enter a
phone number into textbox1, and then I want textbox2 to be populated
from another sheet based on the value in textbox1, just like a lookup
table. So the name of the person whose phone number is in textbox1
will appear in textbox2. Does anyone know how to do this?

thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default using VLOOKUP in a text box

I created a small userform -- two textboxes and a commandbutton.

This was the code behind the userform:

Option Explicit
Private Sub CommandButton1_Click()

Dim res As Variant
Dim LookUpRng As Range

If Me.TextBox1.Value = "" Then
Beep
Exit Sub
End If

Set LookUpRng = ThisWorkbook.Worksheets("Sheet1").Range("A:B")

'look for a text match 123-124-1235
res = Application.VLookup(Me.TextBox1.Value, LookUpRng, 2, False)
If IsError(res) Then
If IsNumeric(Me.TextBox1.Value) Then
'look for a number match
res _
= Application.VLookup(Val(Me.TextBox1.Value), LookUpRng, 2, False)
End If
End If

If IsError(res) Then
'not found either way
res = "No Match!"
End If

Me.TextBox2.Value = res

End Sub


Andrew wrote:

Hello,
I have a user form with textbox1 and textbox2. I want to enter a
phone number into textbox1, and then I want textbox2 to be populated
from another sheet based on the value in textbox1, just like a lookup
table. So the name of the person whose phone number is in textbox1
will appear in textbox2. Does anyone know how to do this?

thanks


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default using VLOOKUP in a text box

On May 5, 11:03*am, Dave Peterson wrote:
I created a small userform -- two textboxes and a commandbutton.

This was the code behind the userform:

Option Explicit
Private Sub CommandButton1_Click()

* * Dim res As Variant
* * Dim LookUpRng As Range

* * If Me.TextBox1.Value = "" Then
* * * * Beep
* * * * Exit Sub
* * End If

* * Set LookUpRng = ThisWorkbook.Worksheets("Sheet1").Range("A:B")

* * 'look for a text match 123-124-1235
* * res = Application.VLookup(Me.TextBox1.Value, LookUpRng, 2, False)
* * If IsError(res) Then
* * * * If IsNumeric(Me.TextBox1.Value) Then
* * * * * *'look for a number match
* * * * * * res _
* * * * * * *= Application.VLookup(Val(Me.TextBox1.Value), LookUpRng, 2, False)
* * * * End If
* * End If

* * If IsError(res) Then
* * * * 'not found either way
* * * * res = "No Match!"
* * End If * *

* * Me.TextBox2.Value = res

End Sub

Andrew wrote:

Hello,
I have a user form with textbox1 and textbox2. *I want to enter a
phone number into textbox1, and then I want textbox2 to be populated
from another sheet based on the value in textbox1, just like a lookup
table. *So the name of the person whose phone number is in textbox1
will appear in textbox2. *Does anyone know how to do this?


thanks


--

Dave Peterson


Thank you. This is exactly what I was looking for.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vlookup Text Richard Excel Discussion (Misc queries) 1 July 28th 09 06:24 PM
using a vlookup to enter text into rows beneath the vlookup cell Roger on Excel Excel Programming 1 November 29th 07 12:09 PM
VLOOKUP (with text) Woody13 Excel Discussion (Misc queries) 3 January 24th 06 07:20 PM
Vlookup a value and text raboone Excel Discussion (Misc queries) 1 June 8th 05 08:04 PM
Vlookup and text Adam[_9_] Excel Programming 8 January 19th 04 07:17 PM


All times are GMT +1. The time now is 10:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"