Populate textbox dependent on combobox value

Mikeymike_W

Board Regular
Hi There,

I have no idea where to start with this so would love some help.

I have four comboboxes with twelve colours on the list (each has an identical list). Say the colour "Red" is selected in the combobox i want the textbox to populate with information which corresponds to the Value "Red"; this information is on sheet 2.
Now if they choose a second colour from combobox 2 i'd then like that to be added on to the information that was acquired from combox one and inserted within the textbox... the same would apply for combobox 3 & 4.

I hope this makes sense.

Thanks in advance for any help you can give,

Mike
 

My Aswer Is This

Well-known Member
We always need specific details.
Like you said:

i want the textbox to populate with information which corresponds to the Value "Red"; this information is on sheet 2.

You did not say where on sheet 2

And corresponds is a vague term.
 

Mikeymike_W

Board Regular
So the information is in a table on sheet 2 called "foundation". This table has the twelve colours in column A and next to them in column B is the corresponding data which i would want to appear in the textbox.
 

My Aswer Is This

Well-known Member
So if the colors are in a Table why do you need the comboboxes?

You said:

This table has the twelve colours in column A

I have four comboboxes with twelve colours on the list (each has an identical list).

I need to know what will activate the script?

When you choose a value from a combobox or click on a cell in the Table


 

Mikeymike_W

Board Regular
I'm not too sure how else to say it.

In sheet one there are 4 combo boxes, each one has a list of twelve colours. When a colour is selected I would like information about that colour to appear in a text box (textbox1) on sheet one.
The information about each colour which I want to appear in textbox1 is located within a table named "foundation" in sheet2.

So what I need to happen is when I select a colour in combobox1 it will search for that colour in the table in sheet 2 then take the information about that colour from the table and place it in textbox1 in sheet1.

I also want the same thing to happen for the other combo boxes but without overwriting the information already in textbox1 from the previous combo box.

The trigger would be selecting the item in the combo box. Perhaps a worksheet change or just a change event in the combo box??
 

My Aswer Is This

Well-known Member
I would like for you to give me a couple examples.


So if in Combobox you select Red

You said:
So what I need to happen is when I select a colour in combobox1 it will search for that colour in the table in sheet 2 then take the information about that colour from the table and place it in textbox1 in sheet1.

So we search Column 1 of the table for red and Take what information from the Table??

Do you mean Take information from column 2 of the table

Tables do not have columns A and B

A Table has column like column 1 column 2 column 3

That is because a Table may be in column A B and C or it may be columns F G and H

So table columns are referred to as Table Named:
Sheet2 Listobject("foundation").column 1
 
Last edited:

Mikeymike_W

Board Regular
Hi,

So in the table the information is in the second column, the colours are in the first column.
So if "Red" is in the first column then against it in the second column would be "A deep rich colour, passionate and violent"... this is the information i want to appear in the textbox
In column one all the colours are listed and against each (in column two) is information about that colour which i want to appear in the textbox dependent on the choices made in the combobox. Again I want this to happen so that if colours are chosen in all four comboboxes that the information in the textbox is not deleted but added onto the information from the other comboboxes.

Many thanks,

Mike
 

My Aswer Is This

Well-known Member
You would need to put this code in all 4 ComboBoxes

The script searches Sheet(2).Table named "foundation" Column(1) and adds the value in column(2) of the Table into TextBox1 on sheet1

Code:
Private Sub ComboBox1_Change()
'Modified  9/20/2019  5:47:05 AM  EDT
Dim SearchString As String
Dim SearchRange As Range
SearchString = ComboBox1.Value  ' Modify for each ComboBox
Set SearchRange = Sheets(2).ListObjects("foundation").ListColumns(1).Range.Find(SearchString, LookIn:=xlValues, lookat:=xlWhole)
If SearchRange Is Nothing Then MsgBox SearchString & "  Not Found": Exit Sub
TextBox1.Value = TextBox1.Value & SearchRange.Offset(, 1).Value
End Sub
 

Some videos you may like

This Week's Hot Topics

Top