PDA

Click to See Complete Forum and Search --> : Excel Combo Box


VB4fun
Dec 30th, 2005, 04:36 PM
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)

zaza
Dec 31st, 2005, 05:09 AM
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

VB4fun
Dec 31st, 2005, 12:31 PM
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.)

newbiekea
Jan 1st, 2006, 08:46 AM
something like this?

'5 because your values starts at row 5
for i = 5 to activesheet.usedRange.rows.count 'last row in excelsheet
'add to combobox if value in cell is equal to value in textbox
if trim(me.txtSelection.text) = trim(cells(i, 1)) then
cboAbailable.additem me.txtSelection.text
end if
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?

VB4fun
Jan 1st, 2006, 10:38 AM
newbiekea,

Thanks, that at least gets me going down a path. I think it is what I am looking for, thanks!