Populating combo box from pivot table

bjorgen

New Member
Joined
Aug 23, 2011
Messages
33
I'm trying to populate a combo box based on a pivot table

I'm able to get the first one populated and added to the filter but there are 6 more filters that I'd like to be able to set hierarchically.

Assume that I have the first combobox (combobox1) populated and have just fed that value into the pivot table filter. I'd like to then have the code run through each filter based on hierarchy 2 and if there is no data for that filter based on the top filter then don't add it to combobox 2, otherwise do add it.

Basically it's a way of setting dependent combo boxes hierarchically.

Range B2 is the dropdown for the filter, so changing it for each pivotitem. Range C11 is where the cell would be blank should the pivottable contain no data.

It's breaking at the "selection.value = pvtItem" line with run time error 1004, application defined or object defined error.

Any help is greatly appreciated!

Code:
dim pvtitem = as excel.pivotitem
....
    With UserForm1.ComboBox2
    For Each pvtItem In ActiveSheet.PivotTables("pepperoni").PivotFields("HierarchyFilter2").PivotItems


            Range("b2").Select
            Selection.Value = pvtItem
                       
            If WorksheetFunction.CountA(Range("c11")) <> 0 Then .AddItem
    Next
    End With
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
I was able to get this working, the problem being a bad data value of "" instead of (blanks) in the dropdown.
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,919
Members
452,949
Latest member
beartooth91

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
Back
Top