我在同一张表上有一个comboBox
和几个数据透视表。 comboBox
根据所选内容更新数据透视表过滤器。
问题是,当数据透视表刷新(设置新过滤器)时,它将激活组合框_click
功能,开始循环。
有解决方法吗?为什么数据透视表会刷新激活组合框?
这是_Click事件中的代码:
Private Sub cmb_SkuSelect_Click()
Dim xlSheetSort As Worksheet
Dim lastRow As Long
Dim xlCell As Range
Dim skuValue As Integer
Set xlSheetSort = ActiveWorkbook.Worksheets("Sort")
lastRow = xlSheetSort.Range("A1").End(xlDown).Row
With xlSheetSort.Range("B1:B" & lastRow)
Set xlCell = .Find(cmb_SkuSelect.Value, LookIn:=xlValues)
If Not xlCell Is Nothing Then
skuValue = xlSheetSort.Range("A" & xlCell.Row).Value
End If
End With
updatePivot skuValue
End Sub
updatePivot:
Public Sub updatePivot(ByVal sku As Integer)
Dim pt As PivotTable
Dim pt2 As PivotTable
Dim Field As PivotField
Dim Field2 As PivotField
Dim newSku As String
Set pt = Worksheets("Sku Inventory").PivotTables("SkuInfo")
Set Field = pt.PivotFields("Sku Number")
Set pt2 = Worksheets("Sku Inventory").PivotTables("InventoryInfo")
Set Field2 = pt2.PivotFields("Sku Number")
newSku = sku
With pt
Field.CurrentPage = newSku
pt.RefreshTable
End With
With pt2
Field2.CurrentPage = newSku
pt2.RefreshTable
End With
End Sub
答案 0 :(得分:0)
Public Sub updatePivot(ByVal sku As Integer)
Dim pt As PivotTable
Dim pt2 As PivotTable
Dim Field As PivotField
Dim Field2 As PivotField
Dim newSku As String
Set pt = Worksheets("Sku Inventory").PivotTables("SkuInfo")
Set Field = pt.PivotFields("Sku Number")
Set pt2 = Worksheets("Sku Inventory").PivotTables("InventoryInfo")
Set Field2 = pt2.PivotFields("Sku Number")
newSku = sku
With pt
With Field
.Orientation = xlHidden
pt.RefreshTable
.Orientation = xlPageField
.CurrentPage = newSku
End With
End With
With pt2
With Field2
.Orientation = xlHidden
pt2.RefreshTable
.Orientation = xlPageField
.CurrentPage = newSku
End With
End With
End Sub