我的团队正在Excel中创建一个“客户信息中心”,它在各个标签上以数据透视表的形式显示指标。我们已经创建了几个SQL Server连接来提取我们填充数据透视表所需的数据。这些连接使用存储过程,存储过程的参数从几个单元格中收集。存储过程如下所示:
{CALL OPE.OPE.uspCSDashboard(?,?,?,?)}
该报告运行良好,我们的内部客户喜欢它。我们最近在试图拉大型系统时遇到了一个问题。大型系统大约56列~65,000行。结果是Excel似乎崩溃或超时。当我点击“运行报告”时,它就像它正常工作一样,然后它在顶部变灰并说(没有响应)。有时它会在拉动较小的数据集时恢复(56X28,000),但在等待大约五分钟后似乎无法恢复。
在SQL Server中为大型系统运行存储过程时。它在大约七秒钟内完成。
有谁知道为什么需要这么久?在运行大型系统时,我该怎么做才能解决崩溃错误?以下是所有代码:
Sub FilterPivotField(Field As PivotField, Value)
Application.ScreenUpdating = False
With Field
On Error Resume Next
If .Orientation = xlPageField Then
.CurrentPage = Value
ElseIf .Orientation = xlRowField Or .Orientation = xlColumnField Then
Dim i As Long
On Error Resume Next ' Needed to avoid getting errors when manipulating PivotItems that were deleted from the data source.
' Set first item to Visible to avoid getting no visible items while working
.PivotItems(1).Visible = True
For i = 2 To Field.PivotItems.Count
If .PivotItems(i).Name = Value Then _
.PivotItems(i).Visible = True Else _
.PivotItems(i).Visible = False
Next i
If .PivotItems(1).Name = Value Then _
.PivotItems(1).Visible = True Else _
.PivotItems(1).Visible = False
End If
End With
Application.ScreenUpdating = True
End Sub
Sub RunReport()
'Aliasing PivotTable Function
Dim pt As PivotTable
'Turn Screen Updates Off
Application.ScreenUpdating = False
'Unprotect Sheets
Worksheets("Hospital Dashboard").Unprotect ("escan")
Worksheets("Reports Summary").Unprotect ("escan")
Worksheets("Exclusion Report").Unprotect ("escan")
Worksheets("Billing Deadline Report").Unprotect ("escan")
'Unhide Certain Tabs
Sheets("DetailData").Visible = True
Sheets("HiddenPivotTables").Visible = True
'Refresh Tables
Application.Goto reference:="Table_Query_from_CustomerDashboard"
Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
Application.Goto reference:="Table_Query_from_CustomerDashboard_1"
Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
'Refresh PT Tables
For Each Worksheet In ThisWorkbook.Worksheets
For Each pt In Worksheet.PivotTables
pt.PivotCache.Refresh
Next pt
Next
'call filter
FilterPivotField Worksheets("Hospital Dashboard").PivotTables("PivotTable7").PivotFields("IsCoded"), "0"
FilterPivotField Worksheets("Hospital Dashboard").PivotTables("PivotTable7").PivotFields("IsInvoiced"), "0"
FilterPivotField Worksheets("Hospital Dashboard").PivotTables("PivotTable8").PivotFields("IsCoded"), "0"
FilterPivotField Worksheets("Hospital Dashboard").PivotTables("PivotTable8").PivotFields("IsInvoiced"), "0"
FilterPivotField Worksheets("Billing Deadline Report").PivotTables("PivotTable1").PivotFields("IsCoded"), "0"
FilterPivotField Worksheets("Billing Deadline Report").PivotTables("PivotTable1").PivotFields("IsExcluded"), "0"
FilterPivotField Worksheets("HiddenPivotTables").PivotTables("PivotTable5").PivotFields("IsCoded"), "0"
FilterPivotField Worksheets("HiddenPivotTables").PivotTables("PivotTable5").PivotFields("IsExcluded"), "0"
'Hide Certain Tabs
Sheets("DetailData").Visible = False
Sheets("HiddenPivotTables").Visible = False
'Protect Sheets
Worksheets("Hospital Dashboard").Protect "escan", _
DrawingObjects:=False, _
Contents:=True, _
Scenarios:=False, _
userInterfaceOnly:=False, _
AllowFormattingCells:=False, _
AllowFormattingColumns:=False, _
AllowFormattingRows:=False, _
AllowInsertingColumns:=False, _
AllowInsertingRows:=False, _
AllowInsertingHyperlinks:=False, _
AllowDeletingColumns:=False, _
AllowDeletingRows:=False, _
AllowSorting:=False, _
AllowFiltering:=False, _
AllowUsingPivotTables:=True
Worksheets("Reports Summary").Protect "escan", _
DrawingObjects:=False, _
Contents:=True, _
Scenarios:=False, _
userInterfaceOnly:=False, _
AllowFormattingCells:=False, _
AllowFormattingColumns:=False, _
AllowFormattingRows:=False, _
AllowInsertingColumns:=False, _
AllowInsertingRows:=False, _
AllowInsertingHyperlinks:=False, _
AllowDeletingColumns:=False, _
AllowDeletingRows:=False, _
AllowSorting:=False, _
AllowFiltering:=False, _
AllowUsingPivotTables:=True
Worksheets("Exclusion Report").Protect "escan", _
DrawingObjects:=False, _
Contents:=True, _
Scenarios:=False, _
userInterfaceOnly:=False, _
AllowFormattingCells:=False, _
AllowFormattingColumns:=False, _
AllowFormattingRows:=False, _
AllowInsertingColumns:=False, _
AllowInsertingRows:=False, _
AllowInsertingHyperlinks:=False, _
AllowDeletingColumns:=False, _
AllowDeletingRows:=False, _
AllowSorting:=False, _
AllowFiltering:=False, _
AllowUsingPivotTables:=True
Worksheets("Billing Deadline Report").Protect "escan", _
DrawingObjects:=False, _
Contents:=True, _
Scenarios:=False, _
userInterfaceOnly:=False, _
AllowFormattingCells:=False, _
AllowFormattingColumns:=False, _
AllowFormattingRows:=False, _
AllowInsertingColumns:=False, _
AllowInsertingRows:=False, _
AllowInsertingHyperlinks:=False, _
AllowDeletingColumns:=False, _
AllowDeletingRows:=False, _
AllowSorting:=False, _
AllowFiltering:=False, _
AllowUsingPivotTables:=True
'Unhide Detail Data
Worksheets("DetailData").Activate
Rows("2:500000").Hidden = False
'Getting back to home sheet
Worksheets("Home").Select
'Setting data last update to value
Worksheets("home").Range("c6").Value = "=OFFSET(DetailData!aq8,0,0)"
'Message Box to let the CSR know data has been refreshed
Dim Done As String
Done = "Data is finished updating!"
MsgBox (Done)
End Sub
答案 0 :(得分:0)
这不确定,但问题可能只是你正在搞乱的数据量。我可以经常使用大量数据崩溃Excel,如果你在每次运行时导入数据,我的钱就是你有数十万行数据已经根据需要导入和按摩。
根据代码中的内容,您可以关闭计算%Lf
以帮助加快速度。您可以而且应该使用表的名称而不是选择它们(作为一般规则,您的代码中永远不需要Application.Calculation = xlManual
)。如果您不知道它们的透视表是什么,则在刷新表以获取名称时记录宏,或者单击一个并查看A列上方的小窗口,该列通常显示您选择的单元格。 / p>
这些应该会有所帮助,但它们可能无法解决问题,具体取决于工作簿中的数据总量(以及图表,格式等)。
如果是这种情况,您可能需要将工作簿拆分,以便任何一个工作簿中的内容更少(例如,每个工作簿中只有一个数据透视表,以及提供该数据透视表的任何数据和公式)。 / p>