首页 > 解决方案 > 您能否帮助在 Pivot 中使用过滤后的名称创建工作簿

问题描述

这是创建带有两个过滤器的数据透视表,第一个过滤器是名称,第二个过滤器是日期,所以当我们在第二个过滤器中选择最新日期时,它需要使用所有过滤器名称创建单独的工作簿,我尝试使用此代码

'''Sub arcpivot3()
Dim myPivotField As PivotField
Dim filterValue As String
Dim vendorname As String
Dim myString As String
Dim fp As Worksheet
Dim vr As Worksheet
Dim temp, ALastRow, BLastRow As Integer
Dim VendorNamesArray(100) As String
Set fp = Worksheets("2nd Pivot")
ALastRow = fp.Range("A" & Rows.Count).End(xlUp).Row
Dim ws As Worksheet
Set ws = Worksheets("secondpivot")
Dim pT As PivotTable
Set pT = ws.PivotTables("secondpivot_table")
Dim pF As PivotField
Set pF = pT.PivotFields("Principal Vendor Name")
pF.EnableMultiplePageItems = True
pF.CurrentPage = "(All)"
For i = 1 To pF.PivotItems.Count
If i < pF.PivotItems.Count Then
pF.PivotItems(i).Visible = False
Else
pF.PivotItems(i).Visible = True
End If
Next i
End With
a = ThisWorkbook.Worksheets.Count
For i = 1 To a
If ThisWorkbook.Worksheets(i).Name <> "vendor" Then
Set wb = Workbooks.Add
ThisWorkbook.Worksheets(i).Copy before:=wb.Worksheets(1)
If (VendorNamesArray(i) <> "") Then
wb.SaveAs "E:\ARC Attachments\" & groupname & "-" & reqid & "\" & VendorNamesArray(i) & ".xlsx"
wb.Close savechanges = True
Else
wb.SaveAs "E:\ARC Attachments\" & groupname & "-" & reqid & "\" & ActiveSheet.Name & ".xlsx"
wb.Close savechanges = True
End If
End If
Next i
End Sub'''

错误是它正在创建工作簿但不像expexted

标签: excelvbapivot

解决方案


推荐阅读