我怎样才能使这段代码更有效率,使其运行得更快?

How can I make this code more efficient so that it runs quicker?

我试图隐藏行以便只显示特定的零售商数据,由于报告的布局,数据不可过滤。我首先取消隐藏所有行作为重置,然后手动隐藏与零售商无关的行,直到只保留点击的零售商信息。

然而,这样做的速度很慢,我需要一种我能理解的更快的方法。没有过滤数据的标准。只是点击按钮上的零售商名称。

我的代码显示了执行此操作的手动缓慢方式。

Sub SummaryRetailer1Only()

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

'Resets hidden rows by showing everything.
ActiveSheet.Rows("2:480").EntireRow.Hidden = False

'Hides all rows that don't show data for Retailer1.
ActiveSheet.Rows("18:21").EntireRow.Hidden = True
ActiveSheet.Rows("37:48").EntireRow.Hidden = True
ActiveSheet.Rows("54:57").EntireRow.Hidden = True
ActiveSheet.Rows("73:84").EntireRow.Hidden = True
ActiveSheet.Rows("88:129").EntireRow.Hidden = True
ActiveSheet.Rows("261:376").EntireRow.Hidden = True
ActiveSheet.Rows("390:393").EntireRow.Hidden = True
ActiveSheet.Rows("409:420").EntireRow.Hidden = True
ActiveSheet.Rows("424:427").EntireRow.Hidden = True
ActiveSheet.Rows("443:454").EntireRow.Hidden = True

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub

代码工作正常我只是想要一种我假设使用一些变量的方法,以便它运行得更快。

另一种方式:

Option Explicit

Sub SummaryRetailer1Only()

    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

    With ThisWorkbook.Worksheets("Sheet1") '<- It s better to create a with statement with the sheet you want to use insead of activesheet

        'Resets hidden rows by showing everything.
        .Rows("2:480").EntireRow.Hidden = False

        'Hides all rows that don't show data for Retailer1.
        Union(.Rows("18:21"), .Rows("37:48"), .Rows("54:57"), .Rows("73:84"), .Rows("88:129"), .Rows("261:376"), _
                .Rows("390:393"), .Rows("409:420"), .Rows("424:427"), .Rows("443:454")).EntireRow.Hidden = True

    End With

    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True

End Sub