使用按钮运行时我的宏运行速度更快,但从开发人员窗格运行时运行速度变慢

时间:2018-05-11 18:07:53

标签: excel vba

以两种不同的方式在Excel中运行相同的VBA代码。 1.表格控制按钮(时间--1.5秒)。 2.手动运行宏(时间 - 6秒)

以下是代码。代码是自动分组行

Sub Autogroup()
time1 = Timer

 Dim i As Integer, LastRow As Integer

 'Application.ScreenUpdating = False

     LastRow = Cells(Rows.Count, 1).End(xlUp).Row

    Cells.Select
    Selection.ClearOutline

    For i = 9 To LastRow

    'For i,#,# - the (#)number is the column number for the GROUP header on the excel

        If Cells(i, 6) <> "" Then

            Cells(i, 6).EntireRow.Group

        ElseIf Cells(i, 13) <> "" Then

            Cells(i, 13).EntireRow.Group

        ElseIf Cells(i, 22) <> "" Then

            Cells(i, 22).EntireRow.Group

        End If

    Next i

    ActiveSheet.Outline.ShowLevels RowLevels:=1
    ActiveSheet.Calculate
    Cells(1, 1).Select

 'Application.ScreenUpdating = True

 MsgBox Timer - time1

End Sub

0 个答案:

没有答案