How to auto update textbox1 with data from 2 different combo boxes?

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. Windows
Hi Goodmorning, hope you can help me please with some VBA code please, I have a userform called ‘Userform6’, andin this I have a dropdown box which is named ‘ComboBox1’ which has a list ofwords for example, Stores, Late start, Sickness etc. Then I have another comboboxcalled ‘ComboBox2’ which has a list of people’s names, then I have a textboxcalled ‘TextBox1’ which is for postcode and I want this to automatically updatewhen stores is listed in the ComboBox1 and the name is highlighted in combobox2.
In sheet ’INDAY LISTS’ the stores postcodes are in row L2 to lastrow and the names are inrow D2 to last row.



I hope youcan help?
 
Last edited:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi good afternoon, I really hope you can help with this please, I am quite new to this and really stuck.
 
Upvote 0
Try this

Code:
Private Sub ComboBox2_Change()
    Dim sh As Worksheet
    
    If ComboBox1.ListIndex = -1 Then Exit Sub
    
    Set sh = Sheets("INDAY LISTS")
    Set f = sh.Range("A:A").Find(ComboBox2.Value, LookIn:=xlValues, lookat:=xlWhole)
    If Not f Is Nothing Then
        TextBox1.Value = sh.Cells(f.Row, "L").Value
    Else
        MsgBox "Dont exists"
    End If
End Sub
 
Upvote 0
Hi thank you for the code, I have changed it to textbox3 and row I (my mistake) but when I click on stores on combobox1 and highlight the name in combobox2 I get the msg box pop up and the postcode doesn't populate in textbox3. The postcode are in sheet 'IN DAY LISTS' in row I. thanks for your help and hope you can advise please. much appreciated.
Code:
Private Sub ComboBox2_Change()
    Dim sh As Worksheet
    
    If ComboBox1.ListIndex = -1 Then Exit Sub
    
    Set sh = Sheets("IN DAY LISTS")
    Set f = sh.Range("A:A").Find(ComboBox2.Value, LookIn:=xlValues, lookat:=xlWhole)
    If Not f Is Nothing Then
        TextBox3.Value = sh.Cells(f.Row, "I").Value
    Else
        MsgBox "Dont exists"
    End If
End Sub
 
Upvote 0
with combobox1 as I have numerous things in the list I only want the textbox updated if 'Stores' is selected in the combobox. hope you can help please.
 
Upvote 0
with combobox1 as I have numerous things in the list I only want the textbox updated if 'Stores' is selected in the combobox. hope you can help please.

You can put an example of the data on the sheet.
What data do you select in the combobox1, what data do you select in the combo2 and what data do you expect as a result in the textbox3?
 
Upvote 0
Hi in textbox 3 I would like the post code to auto populate when a name is selected from combobox2 and stores is selected from the dropdown list in combobox1. for example in sheet 'IN DAY LISTS' for combobox 1 the list is located in row E and I have stores, Vehicle issues, late start, for names is located in Row D and the postcodes are in Row I,
 
Upvote 0
Hi in textbox 3 I would like the post code to auto populate when a name is selected from combobox2 and stores is selected from the dropdown list in combobox1. for example in sheet 'IN DAY LISTS' for combobox 1 the list is located in row E and I have stores, Vehicle issues, late start, for names is located in Row D and the postcodes are in Row I,

It is clear to me, I have to fill in the textbox3.
What I do not understand is the relationship of the combobox1 and the combobox2



Another small detail
Row D and the postcodes are in Row I

Must be
Column D and the postcodes are in Column I


You can put an example of the data on the sheet.
What data do you select in the combobox1, what data do you select in the combo2 and what data do you expect as a result in the textbox3?

You could upload a copy of your file or image file to a free site such www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0
hi combobox2 has a list of peoples names to select from which is in column D, and in combobox1 is a list of reasons, which you can select, but when they select 'stores' from combbox1 and a name from comboox2 I want the postcode to the stores to automatically updated in textbox3. The postcode for the stores for each name is in in column I. hope this makes sense.
 
Upvote 0
hi combobox2 has a list of peoples names to select from which is in column D, and in combobox1 is a list of reasons, which you can select, but when they select 'stores' from combbox1 and a name from comboox2 I want the postcode to the stores to automatically updated in textbox3. The postcode for the stores for each name is in in column I. hope this makes sense.


Is it too much trouble for you to put an example, an image or a file?

Please Note
-----------------------
One thing you must keep in mind when you ask a question in a forum... the people you are asking to help you know absolutely nothing about your data, absolutely nothing about how it is laid out in the workbook, absolutely nothing about what you want done with it and absolutely nothing about how whatever it is you want done is to be presented back to you as a result... you must be very specific about describing each of these areas, in detail, and you should not assume that we will be able to "figure it out" on our own. Remember, you are asking us for help... so help us to be able to help you by providing the information we need to do so, even if that information seems "obvious" to you (remember, it is only obvious to you because of your familiarity with your data, its layout and the overall objective for it).
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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