Avatar of hkgal
hkgal
 asked on

Excel dynamic combobox

I have a userform in Excel that would like to populate items based on another hidden worksheet in the workbook, table structure like:

Team               Agent
1                      Leo
1                      Mike
2                       Tim
2                      Eric
2                       John

The first combox box can link up to the values in column "Team" (i.e. 1,2,..)
and when i select Team 1 in first combobox, The names of agents for respective teams will pop up in 2nd combobox (i.e. Leo, Mike)

Thanks!
Microsoft ExcelVB ScriptVisual Basic Classic

Avatar of undefined
Last Comment
StephenJR

8/22/2022 - Mon
Saqib Husain

You would need something like

private sub combobox1_change()
set ws=thisworkbook.sheets("sheetname")
combobox2.clear
for each cel in ws.range("A:A")
if cel.value=combobox1.value then combobox2.add cel.offset(0,1).value
next cel
end sub
StephenJR

Simple example in attachment. Change the first combobox and see what happens. It used named ranges for your teams.
Book5.xls
hkgal

ASKER
Hi StephenJR, ur sample is pretty simple. but I don't know why when I incorporate into my work, I was promopted with "could not set rowsource property"??

i attached my sample....pls help testing.xls
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
hkgal

ASKER
and actually i would like to hide the raw data worksheet and only shows "result" worksheet

but when i put:

sheets("result").activate

at the end of sub userform_initialize()....it doesn't work 2..
ASKER CERTIFIED SOLUTION
StephenJR

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
hkgal

ASKER
Very timely and helpful
StephenJR

Glad it worked.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.