在我的电子表格中,我有可变数据;但是,我有一组特定的属性,如果/当它们确实出现在该周的数据运行中时,我希望对其进行过滤。如果它们没有出现,我希望数据透视表过滤器跳过它并继续下一个。 不幸的是,当我尝试运行宏时,我不断收到调试错误。有人可以帮忙吗?
即。 如果“1G1N13S2”不在变量[raw]数据中,它会直接带我到VBA进行调试,而不是跳过它(无论是假还是真)继续下一个ID#。
'PivotTable
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=ActiveSheet.UsedRange). _
CreatePivotTable TableDestination:="", TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
' BCA_Other Macro
With ActiveSheet.PivotTables("PivotTable1").PivotFields("ACTIVITY_ID")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("SUM_$"), "Count of SUM_$", xlCount
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of SUM_$")
.Caption = "Sum of SUM_$"
.Function = xlSum
.NumberFormat = "#,##0.00_);[Red](#,##0.00)"
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("WK_END_DATE")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("WK_END_DATE")
.PivotItems("(blank)").Visible = False
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("ANALYSIS_TYPE")
.Orientation = xlPageField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").PivotFields("ANALYSIS_TYPE"). _
CurrentPage = "ACT"
With ActiveSheet.PivotTables("PivotTable1").PivotFields("BUS_UNIT_GL_FROM")
.Orientation = xlPageField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").PivotFields("BUS_UNIT_GL_FROM"). _
CurrentPage = "AV"
'Activity ID Filter
With ActiveSheet.PivotTables("PivotTable1").PivotFields("ACTIVITY_ID")
.PivotItems("1G1N13S2").Visible = False
.PivotItems("1G1N2SAN").Visible = False
.PivotItems("1G1N5ACC").Visible = False
.PivotItems("1G1N5SCI").Visible = False
.PivotItems("1G1N5SDV").Visible = False
.PivotItems("1G1N5SMS").Visible = False
.PivotItems("1G1N5SST").Visible = False
.PivotItems("1G1N9BAT").Visible = False
.PivotItems("1G1N9EBT").Visible = False
.PivotItems("1G1N9EPL").Visible = False
.PivotItems("E6T66ZAV").Visible = True
.PivotItems("E6T66ZB3").Visible = True
.PivotItems("E6T66ZB4").Visible = True
.PivotItems("E6T66ZB5").Visible = True
.PivotItems("E6T66ZCU").Visible = True
.PivotItems("E6T66ZDX").Visible = True
.PivotItems("E6T66ZE9").Visible = True
.PivotItems("E6T66ZIL").Visible = True
.PivotItems("E6T66ZIS").Visible = True
.PivotItems("E6T66ZIV").Visible = True
.PivotItems("E6T66ZIZ").Visible = True
.PivotItems("E6T66ZJ6").Visible = True
.PivotItems("E6T66ZJ8").Visible = True
.PivotItems("E6T66ZJA").Visible = True
.PivotItems("EMAD0005").Visible = False
.PivotItems("EMADF006").Visible = False
.PivotItems("F8800YN5").Visible = True
.PivotItems("F8800YNU").Visible = True
.PivotItems("F8800YNW").Visible = True
.PivotItems("F8800YPM").Visible = True
End With
'Add new tabs for Hours and rename tabs to Dollars and Hours
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "BCA_Other_Dlrs"
Sheets("BCA_Other_Dlrs").Select
Sheets("BCA_Other_Dlrs").Copy Before:=Sheets(1)
Range("B18").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("Sum of SUM_$").Orientation _
= xlHidden
With ActiveSheet.PivotTables("PivotTable1").PivotFields("SUM_HOURS")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable1").PivotFields("SUM_HOURS").Orientation = _
xlHidden
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("SUM_HOURS"), "Count of SUM_HOURS", xlCount
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of SUM_HOURS")
.Caption = "Sum of SUM_HOURS"
.Function = xlSum
.NumberFormat = "#,##0.0_);[Red](#,##0.0)"
答案 0 :(得分:1)
所以,我已经得到了如何解决这个问题的答案。
On Error Resume Next
With ActiveSheet.PivotTables("PivotTable1").PivotFields("ACTIVITY_ID")
.PivotItems("1G1N13S2").Visible = False
.PivotItems("1G1N2SAN").Visible = False
.PivotItems("1G1N5ACC").Visible = False
.PivotItems("1G1N5SCI").Visible = False
.PivotItems("1G1N5SDV").Visible = False
.PivotItems("E6T66ZJA").Visible = True
End With
On Error Goto 0