Results 1 to 8 of 8

Thread: Populate textbox dependent on combobox value
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Feb 2016
    Posts
    105
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Populate textbox dependent on combobox value

    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

  2. #2
    Board Regular My Aswer Is This's Avatar
    Join Date
    Jul 2014
    Posts
    15,833
    Post Thanks / Like
    Mentioned
    28 Post(s)
    Tagged
    13 Thread(s)

    Default Re: Populate textbox dependent on combobox value

    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.
    Be sure and always test this script on sample data the first time you use this as to avoid any problems with your data. Always trying to learn more and help others where I can. I'm using Excel 2013.
    Patience please Iím not perfect yet. "Memories are forever"

  3. #3
    Board Regular
    Join Date
    Feb 2016
    Posts
    105
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Populate textbox dependent on combobox value

    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.

  4. #4
    Board Regular My Aswer Is This's Avatar
    Join Date
    Jul 2014
    Posts
    15,833
    Post Thanks / Like
    Mentioned
    28 Post(s)
    Tagged
    13 Thread(s)

    Default Re: Populate textbox dependent on combobox value

    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


    Be sure and always test this script on sample data the first time you use this as to avoid any problems with your data. Always trying to learn more and help others where I can. I'm using Excel 2013.
    Patience please Iím not perfect yet. "Memories are forever"

  5. #5
    Board Regular
    Join Date
    Feb 2016
    Posts
    105
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Populate textbox dependent on combobox value

    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??

  6. #6
    Board Regular My Aswer Is This's Avatar
    Join Date
    Jul 2014
    Posts
    15,833
    Post Thanks / Like
    Mentioned
    28 Post(s)
    Tagged
    13 Thread(s)

    Default Re: Populate textbox dependent on combobox value

    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 by My Aswer Is This; Sep 20th, 2019 at 12:13 AM.
    Be sure and always test this script on sample data the first time you use this as to avoid any problems with your data. Always trying to learn more and help others where I can. I'm using Excel 2013.
    Patience please Iím not perfect yet. "Memories are forever"

  7. #7
    Board Regular
    Join Date
    Feb 2016
    Posts
    105
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Populate textbox dependent on combobox value

    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

  8. #8
    Board Regular My Aswer Is This's Avatar
    Join Date
    Jul 2014
    Posts
    15,833
    Post Thanks / Like
    Mentioned
    28 Post(s)
    Tagged
    13 Thread(s)

    Default Re: Populate textbox dependent on combobox value

    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
    Be sure and always test this script on sample data the first time you use this as to avoid any problems with your data. Always trying to learn more and help others where I can. I'm using Excel 2013.
    Patience please Iím not perfect yet. "Memories are forever"

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •