[英]How to apply filter for pivot table through combo box in VBA?
In Pivot Table Facility
field there are 9 different facilities and how to select a particular facility through Combo Box(Using Excel 2007). 在“数据透视表Facility
字段中,有9种不同的设施以及如何通过组合框选择特定设施(使用Excel 2007)。
Below is the code i have tried but it is selecting all 9 facilities. 下面是我尝试过的代码,但它正在选择所有9种设施。
.PivotFields("ProjectCode ").Orientation = xlRowField
With .PivotFields("Facility ") = ComboBox1.Text
' .PivotItems("ABC ").Visible = True
' .PivotItems("DLF ").Visible = False
' .PivotItems("EON ").Visible = False
' .PivotItems("XYZ ").Visible = False
' .PivotItems("SEZ ").Visible = False
' .PivotItems("QAZ ").Visible = False
' .PivotItems("QWE ").Visible = False
' .PivotItems("RMZ ").Visible = False
' .PivotItems("POI ").Visible = False
End With
.PivotFields("Facility ").Orientation = xlColumnField`
ComBox1 source data is selected from named range in sheet1. 从Sheet1中的命名范围中选择ComBox1源数据。
It is giving required result for all 9 facility, 它为所有9个设施提供了所需的结果,
Now how to make a pivot table that takes value from ComboBox? 现在如何制作一个从ComboBox获取价值的数据透视表?
Please help. 请帮忙。
The following code should work. 下面的代码应该工作。 It will run when the command button is clicked. 单击命令按钮后,它将运行。
Private Sub CommandButton1_Click()
With ActiveSheet.PivotTables("Facility").PivotFields("Facility ")
.PivotItems(ComboBox1.Text).Visible = True
For Each Item In .PivotItems
If Item.Value <> ComboBox1.Text Then
Item.Visible = False
End If
Next
End With
Unload UserForm1
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.