我有一个excel工作簿,通过VBA将XMl数据提取到Sheet" Data",根据条件过滤并在" Dashboard"上重建视图。在同一工作簿中的工作表(从第5行开始)。我的代码有效,但速度很慢(不到一分钟,但是很长时间盯着屏幕没有做任何事情),下面的代码使用简单的复制和粘贴来实现我想要的结果,有人告诉我可能是什么我的滞后是由。我查看了vba数组构建,然后只是将工作表设置为该数组,但我无法使其正常工作。谁能协助我克服这个障碍?该守则如下。
Private Sub UpdateDashboard_Click()
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
ActiveWorkbook.RefreshAll
Worksheets("Data").Activate
Sheet2.Rows(5 & ":" & Sheet2.Rows.Count).ClearContents
Dim lngLastRow As Long
Dim Arr1 As Variant
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
With Range("A1", "D" & lngLastRow)
.AutoFilter
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=14, Criteria1:=Worksheets("BTS").Range("A" & (Worksheets("BTS").Range("B2") + 1)).Value
Selection.Range("D:D").Copy Worksheets("Dashboard").Range("A5")
Selection.Range("E:E").Copy Worksheets("Dashboard").Range("B5")
Selection.Range("I:I").Copy Worksheets("Dashboard").Range("C5")
Selection.Range("G:G").Copy Worksheets("Dashboard").Range("D5")
Selection.Range("A:A").Copy Worksheets("Dashboard").Range("E5")
Selection.Range("H:H").Copy Worksheets("Dashboard").Range("F5")
Selection.Range("L:L").Copy Worksheets("Dashboard").Range("G5")
.AutoFilter
End With
Call ImportXMLtoList
Worksheets("BTS").Range("A27").Value = Worksheets("Dashboard").Range("A" & Rows.Count).End(xlUp).Row
Worksheets("Dashboard").Activate
Range("A5:G5").Select
Selection.AutoFilter
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End Sub