excel vba code to autopopulate data to a textbox based on the value in a combo box. My code is not working

J15491

New Member
Joined
Jan 10, 2020
Messages
34
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I need the value in textbox (txtMailTo) to autpopulate the vendor address when the selection in the combobox(cmbVendor) is selected. I have a worksheet(VLookup) with four columns ("A2:D12"). Column A is the Acct number, I need to be able to input a number as the clients account number rather than the tax id or social security number that would come from the lookup worksheet.
Column "B" is the vendors name, Col. "C" is the vendor address and Col. "D" is the City, State, and Zip Code. TextBox(txtMailTo) for the Street Address, ComboBox which has the vendors name in the dropdown list and Textbox(VendorLoc) for the City, St, and zip.

My code for the event change is: Private Sub cmbVendor_Change()
With Me
.txtMailTo = Application.WorksheetFunction.VLookup(Me.cmbVendor, Sheet5.Range("A2:D12"), 2, False.
I think the problem has something to do with this ,2, False, although I'm not sure.

Guidance would be greatly appreciated.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
How do you populate the combobox?
Howmany colums does it have? What is its actual value when an item in the list is selected?
If col. A is the account number and you look for the vendor name you'll never get a match.
What does vlookup return?
 
Upvote 0
How do you populate the combobox?
Howmany colums does it have? What is its actual value when an item in the list is selected?
If col. A is the account number and you look for the vendor name you'll never get a match.
What does vlookup return?
I used vba code to populate the drop down in the combo box. I have 4 columns. Col”A” is the account number. “B” is the Vendor Name “C” is “MailTo. (Street address) and Col. “D” is the city state and zip. I need to have the ability to enter an account number in the textbox named “txtAcct.
The actual value in the cmbVendor is text such as City of xxxxx or Pacific Gas and Electric or something similiar
 
Upvote 0
Like I said: if combo value is vendor name, while column A on sheet5 is account number, vlookup, the way you constructed it, will never find a match. Vlookup looks for a match in the first column of the search range, which in your case contains account number...
I don't know how to explain it better.
The search range should be B2:D12
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top