无法对超过65500行的数据透视表使用宏

时间:2018-06-28 12:18:38

标签: asp.net excel vba excel-vba pivot

我在Excel中将宏用于数据透视表...

当我尝试将数据透视表放入大约80,000行的数据时,我的数据透视表没有出现,但是如果我仅占用65,000行,而没有工作,那么任何人都可以帮助我调试此错误。

这些是我正在使用的VBA代码

Option Explicit

Sub Macro1()

'Declare Variables
Dim PSheet As Worksheet
Dim DSheet As Worksheet
Dim PCache As PivotCache
Dim PTable As PivotTable
Dim PRange As Range
Dim LastRow As Long
Dim LastCol As Long


'Delete Preivous Pivot Table Worksheet & Insert a New Blank Worksheet With Same Name
On Error Resume Next
Application.DisplayAlerts = False
Worksheets("PivotTable").Delete
Sheets.Add Before:=ActiveSheet
ActiveSheet.Name = "PivotTable"
Application.DisplayAlerts = True
Set PSheet = Worksheets("PivotTable")
Set DSheet = Worksheets("Data")


'Define Data Range

    LastRow = DSheet.Cells(Rows.Count, 1).End(xlUp).Row
    LastCol = DSheet.Cells(1, Columns.Count).End(xlToLeft).Column
    Set PRange = DSheet.Cells(1, 1).Resize(LastRow, LastCol)

'Define Pivot Cache
Set PCache = ActiveWorkbook.PivotCaches.Create _
(SourceType:=xlDatabase, SourceData:=PRange). _
CreatePivotTable(TableDestination:=PSheet.Cells(2, 2), _
TableName:="EmployeePivotTable")

'Insert Blank Pivot Table
Set PTable = PCache.CreatePivotTable _
(TableDestination:=PSheet.Cells(1, 1), TableName:="EmployeePivotTable")

'Insert Row Fields
With ActiveSheet.PivotTables("EmployeePivotTable").PivotFields("FilePeriod")
        .Orientation = xlRowField
        .Position = 1
End With
With ActiveSheet.PivotTables("EmployeePivotTable").PivotFields("ProjectNumber")
        .Orientation = xlRowField
        .Position = 2
End With

'Insert Column Fields
With ActiveSheet.PivotTables("EmployeePivotTable").PivotFields("EffectiveFTE")
        .Orientation = xlColumnField
        .Position = 1
End With

'Format Pivot Table
ActiveSheet.PivotTables("EmployeePivotTable").ShowTableStyleRowStripes = True
ActiveSheet.PivotTables("EmployeePivotTable").TableStyle2 = "PivotStyleMedium9"
End Sub

0 个答案:

没有答案