Dynamic Ranges Populate Comboboxes

EXCEL-LENCY

Board Regular
Joined
Feb 9, 2010
Messages
75
Hello,

I have a combobox "VIEW_ITEM_DETAIL_CMB_BX" on the sheet Output that has VBA Code Name "OUTPUT_PAGE". I want to populate that combobox with the dynamic range I've defined as "DYN_COST_DATABASE_ITEMS". This code works when I am populating comboboxed on a userform, but when the combobox is on a sheet, it doesn't work. Help would be greatly appreciated!!

Dim Otpt As Worksheet
Dim Cmb_Bx_Value As Range
Set Otpt = OUTPUT_PAGE

For Each Cmb_Bx_Value In Otpt.Range("DYN_COST_DATABASE_ITEMS")
With Otpt.VIEW_ITEM_DETAIL_CMB_BX
.AddItem Cmb_Bx_Value.Value
.List(.ListCount - 1, 1) = Cmb_Bx_Value.Offset(0, 1).Value
End With
Next Cmb_Bx_Value

Thanks!!
Jason
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

EXCEL-LENCY

Board Regular
Joined
Feb 9, 2010
Messages
75
Can anyone help? I need to populate a combobox on a worksheet with a dynamic range that is contained in the same workbook but a different worksheet.
 

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
Hi, This works for me :-
Code:
Dim Otpt As Worksheet
Dim Cmb_Bx_Value As Range
Set Otpt = Sheets("OUTPUT_PAGE") ' See Here !!!!!
For Each Cmb_Bx_Value In Otpt.Range("DYN_COST_DATABASE_ITEMS")
With VIEW_ITEM_DETAIL_CMB_BX
.AddItem Cmb_Bx_Value.Value
.List(.ListCount - 1, 1) = Cmb_Bx_Value.Offset(0, 1).Value
End With
Next Cmb_Bx_Value
Regards Mick
 

EXCEL-LENCY

Board Regular
Joined
Feb 9, 2010
Messages
75
Thanks Mick. Still isn't working. The Code Name is OUTPUT_PAGE but the Sheet Name is OUTPUT... either way should work in that regard. Not sure why it isn't working...
 

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
Hi, I've altered the cpode slightly to Take account of the sheet name and add reference to ColumnsCount = 2
This was run from another sheet and worked OK.
Code:
[COLOR="Navy"]Sub[/COLOR] MG07Aug41
[COLOR="Navy"]Dim[/COLOR] Otpt [COLOR="Navy"]As[/COLOR] Worksheet
[COLOR="Navy"]Dim[/COLOR] Cmb_Bx_Value [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Set[/COLOR] Otpt = Sheets("OUTPUT")
VIEW_ITEM_DETAIL_CMB_BX.ColumnCount = 2
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Cmb_Bx_Value [COLOR="Navy"]In[/COLOR] Otpt.Range("DYN_COST_DATABASE_ITEMS")
[COLOR="Navy"]With[/COLOR] VIEW_ITEM_DETAIL_CMB_BX
.AddItem Cmb_Bx_Value.Value
.List(.ListCount - 1, 1) = Cmb_Bx_Value.Offset(0, 1).Value
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]Next[/COLOR] Cmb_Bx_Value
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,400
Messages
5,831,411
Members
430,065
Latest member
ctornabe

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top