美好的一天!假设我的excel中有这个Pivot表。从下图中,我想过滤 BrandA 并复制所有品牌 BrandA 并将其粘贴到新工作表中,同样适用于 BrandX 和 BrandZ的即可。
请帮帮我:(
谢谢!
已编辑1 以下是我录制的宏。
Sub MacroTest2()
With ActiveSheet.PivotTables("PivotTable3").PivotFields("Brand")
.PivotItems("BrandA").Visible = False
.PivotItems("BrandZ").Visible = False
End With
Range("A4").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets.Add After:=ActiveSheet
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pivot").Select
ActiveSheet.PivotTables("PivotTable3").PivotFields("Brand").ClearAllFilters
With ActiveSheet.PivotTables("PivotTable3").PivotFields("Brand")
.PivotItems("BrandX").Visible = False
.PivotItems("BrandZ").Visible = False
End With
Range("A4").Select
Range(Selection, Selection.End(xlToRight)).Select
Application.CutCopyMode = False
Selection.Copy
Sheets.Add After:=ActiveSheet
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pivot").Select
ActiveSheet.PivotTables("PivotTable3").PivotFields("Brand").ClearAllFilters
With ActiveSheet.PivotTables("PivotTable3").PivotFields("Brand")
.PivotItems("BrandA").Visible = False
.PivotItems("BrandX").Visible = False
End With
Range("A4:A5").Select
Range(Selection, Selection.End(xlToRight)).Select
Application.CutCopyMode = False
Selection.Copy
Sheets.Add After:=ActiveSheet
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Pivot").Select
End Sub