Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Vlookup in Userform - XL2003

I have a combobox on a userform.

I would like when user selects a Client Name from the combo box the Address
appears in txtAddr1, Addr2,Addr3 .......

I have come up with the code below but clearly I have made a mistake
somewhere.

Thanks very much in advance.

Steve


Private Sub cboClient_Change()

On Error GoTo Error

txtaddr1.Text = Application.WorksheetFunction.VLookup(cboClient.Te xt,
ClientNames!Client_Name, 2, False)

Exit Sub

Error:
txtaddr1.Text = "Error"


End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Vlookup in Userform - XL2003

txtaddr1.Text = Application.WorksheetFunction.VLookup(cboClient.Te xt, _
worksheets("ClientNames").range("Client_Name"), 2, False)



Steve Jones wrote:

I have a combobox on a userform.

I would like when user selects a Client Name from the combo box the Address
appears in txtAddr1, Addr2,Addr3 .......

I have come up with the code below but clearly I have made a mistake
somewhere.

Thanks very much in advance.

Steve

Private Sub cboClient_Change()

On Error GoTo Error

txtaddr1.Text = Application.WorksheetFunction.VLookup(cboClient.Te xt,
ClientNames!Client_Name, 2, False)

Exit Sub

Error:
txtaddr1.Text = "Error"

End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 180
Default Vlookup in Userform - XL2003

you have to make 2 changes here.
First of all change the name of label from Error to something else. You are
using a keyword.

Secondly, declare a variable of variant type and store the result of vlookup
in this variable and later set the text box's text with this variable. Thsi
is because if your vlookup fails, it will return FALSE which you can not
store in text box.

hope this helps
--
Pranav Vaidya
VBA Developer
PN, MH-India


"Steve Jones" wrote:

I have a combobox on a userform.

I would like when user selects a Client Name from the combo box the Address
appears in txtAddr1, Addr2,Addr3 .......

I have come up with the code below but clearly I have made a mistake
somewhere.

Thanks very much in advance.

Steve


Private Sub cboClient_Change()

On Error GoTo Error

txtaddr1.Text = Application.WorksheetFunction.VLookup(cboClient.Te xt,
ClientNames!Client_Name, 2, False)

Exit Sub

Error:
txtaddr1.Text = "Error"


End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Vlookup in Userform - XL2003

I think your first point is very good.

I don't understand about the False stuff, though.

But the way the OP wrote the code (using .worksheetfunction), a mismatch would
cause a runtime error that he avoids with the "on error goto..." line.



Pranav Vaidya wrote:

you have to make 2 changes here.
First of all change the name of label from Error to something else. You are
using a keyword.

Secondly, declare a variable of variant type and store the result of vlookup
in this variable and later set the text box's text with this variable. Thsi
is because if your vlookup fails, it will return FALSE which you can not
store in text box.

hope this helps
--
Pranav Vaidya
VBA Developer
PN, MH-India

"Steve Jones" wrote:

I have a combobox on a userform.

I would like when user selects a Client Name from the combo box the Address
appears in txtAddr1, Addr2,Addr3 .......

I have come up with the code below but clearly I have made a mistake
somewhere.

Thanks very much in advance.

Steve


Private Sub cboClient_Change()

On Error GoTo Error

txtaddr1.Text = Application.WorksheetFunction.VLookup(cboClient.Te xt,
ClientNames!Client_Name, 2, False)

Exit Sub

Error:
txtaddr1.Text = "Error"


End Sub




--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Vlookup in Userform - XL2003

Thanks very much for your help.

"Steve Jones" wrote in message
...
I have a combobox on a userform.

I would like when user selects a Client Name from the combo box the
Address appears in txtAddr1, Addr2,Addr3 .......

I have come up with the code below but clearly I have made a mistake
somewhere.

Thanks very much in advance.

Steve


Private Sub cboClient_Change()

On Error GoTo Error

txtaddr1.Text = Application.WorksheetFunction.VLookup(cboClient.Te xt,
ClientNames!Client_Name, 2, False)

Exit Sub

Error:
txtaddr1.Text = "Error"


End Sub



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
Use named range to fill Userform combobox XL2003? Keith Excel Programming 1 January 5th 07 04:11 PM
Populating Userform ComboBox with worksheet names in XL2003 MAWII Excel Programming 0 August 9th 05 09:07 PM
Vlookup in a userform R D S Excel Discussion (Misc queries) 6 January 26th 05 09:22 PM
Vlookup / Objects help XL2003 Steve Jones Excel Discussion (Misc queries) 0 November 29th 04 05:01 PM
Populate Userform text boxes in VBA with VLookup data from #2 worksheet Laz[_2_] Excel Programming 4 October 8th 03 02:15 AM


All times are GMT +1. The time now is 04:23 AM.

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"