Results 1 to 5 of 5

Thread: Excel Combo Box

  1. #1

    Thread Starter
    Hyperactive Member VB4fun's Avatar
    Join Date
    May 2003
    Location
    too far from Fiji
    Posts
    342

    Excel Combo Box

    I have a combo box, on a form, in excel.

    Is there a way to set the row source, so only certain items from the list appear?

    in SQL it might be something like this:
    SELECT * From tblData WHERE [ColumnData] = txtSelection

    (i know that isn't perfect syntax, but you get the idea)
    Talk does not cook rice.
    -Chinese Proverb

  2. #2
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Excel Combo Box

    Not entirely sure what you mean - do you want the user to select something from the combobox and as a result only certain items appear in a particular Excel column?
    One possibility, without using controls, would be to put an Autofilter on it (Data - Filter menu).

    Alternatively, use the "changed" event of the combobox and just loop through all the items in the column, deleting ones you don't want. You could then do a Sort on the Range of the entire column to bring them all together in order.

    You'd have to repopulate the column first each time though.

    zaza

  3. #3

    Thread Starter
    Hyperactive Member VB4fun's Avatar
    Join Date
    May 2003
    Location
    too far from Fiji
    Posts
    342

    Re: Excel Combo Box

    I will try to be more specific,

    I have a VBA form, on it is txtSelection and cboAvailable.
    In excel, I have a listing (table) with 4 columns, ColumnData, ColmunPartNo, ColumnResult1, ColumnResult2, and ColumnResult3.

    when the user enters a Criteria in txtSelection, the cboAvailable then populates with only data from the list(ColumnData), meeting the criteria of txtSelection.text. ie: Nail

    (Based on that selection then fields Result #1 - #3 are populated.)
    Attached Images Attached Images  
    Talk does not cook rice.
    -Chinese Proverb

  4. #4
    Lively Member
    Join Date
    Aug 2001
    Posts
    103

    Re: Excel Combo Box

    something like this?
    VB Code:
    1. '5 because your values starts at row 5
    2. for i = 5 to activesheet.usedRange.rows.count 'last row in excelsheet
    3.        'add to combobox if value in cell is equal to value in textbox
    4.        if trim(me.txtSelection.text) = trim(cells(i, 1)) then
    5.            cboAbailable.additem me.txtSelection.text
    6.        end if
    7. next i

    off course, this code doesn't check on identique values, it could be that your cbobox is populated with nails twice if nails appears twice in your excel sheet. But maybe this gives u an example of how to do it?

  5. #5

    Thread Starter
    Hyperactive Member VB4fun's Avatar
    Join Date
    May 2003
    Location
    too far from Fiji
    Posts
    342

    Re: Excel Combo Box

    newbiekea,

    Thanks, that at least gets me going down a path. I think it is what I am looking for, thanks!
    Talk does not cook rice.
    -Chinese Proverb

Posting Permissions

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



Click Here to Expand Forum to Full Width