我想根据在另一个工作簿中选择的数据在新工作簿中创建数据透视表。
我尝试了this answer中的代码,但在最后一行代码中出现了引用错误“1004”。
Sub test()
Dim wb As Workbook
Dim ws As Worksheet
Dim pRange As Range
Dim pc As PivotCache
Dim pt As PivotTable
Dim InitialPivotCache As PivotCache
Dim CopyPivotCache As PivotCache
Set wb = Workbooks.Add
Set ws = wb.Worksheets(1)
Set pRange = ThisWorkbook.Sheets(1).Range("A1:B6")
Set pc = ThisWorkbook.PivotCaches.Create(xlDatabase, pRange) 'Cache in ThisWorkbook
Call CountCaches
Set CopyPivotCache = wb.PivotCaches.Create(pc.SourceType, pc.SourceData)
Set pt = ws.PivotTables.Add(CopyPivotCache, Range("A3"), "MyPivotTable")
End Sub
在我设置了“pc”缓存后,我在我的thisworkbook中计算了这段代码的缓存数量,我找到了0个缓存。
Sub CountCaches()
MsgBox "There are " _
& ThisWorkbook.PivotCaches.Count _
& " pivot caches in the active workook."
End Sub
我不知道我的代码有什么问题。我该如何解决?
答案 0 :(得分:0)
public class AV_VM
{
public Tb_AV_Article Article { get; set; }
public List<Tb_AV_Subject> SubjectList { get; set; }
}