Macro Speed

ExcelRoy

Well-known Member
Joined
Oct 2, 2006
Messages
2,540
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I wonder if i may ask a question

I have a simple macro to hide rows of which i have 4 different, 3 of these work fine on one tab but the other is the same as the first one but on another tab but takes ages to run

Would there be a way to speed this up like the other 3?

Sub Hide_1()
With Rows("13:20016")
.EntireRow.Hidden = Not .EntireRow.Hidden
End With
End Sub

Sub Hide_2()
With Rows("20025:20528")
.EntireRow.Hidden = Not .EntireRow.Hidden
End With
End Sub

Sub Hide_3()
With Rows("20537:20590")
.EntireRow.Hidden = Not .EntireRow.Hidden
End With
End Sub

Sub Hide_4()
With Rows("13:20016")
.EntireRow.Hidden = Not .EntireRow.Hidden
End With
End Sub

Many thanks for any help
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi
Try like this
VBA Code:
Sub test()
    Dim rng As Range
    Set rng = Union(Rows("20537:20590"), Rows("20537:20590"), Rows("20537:20590"), Rows("13:20016"))
     With rng
        .EntireRow.Hidden = Not .EntireRow.Hidden
    End With
End Sub
 
Upvote 0
Sometimes the temporary suppression of some events can boost the performance of macros.
So as an alternative to @mohadin's code ...

VBA Code:
Sub ExcelRoy()

    Dim rng     As Range
    Dim bSUpd   As Boolean
    Dim bEvents As Boolean
    Dim bCalc   As XlCalculation

    With Application

        bSUpd = .ScreenUpdating
        bEvents = .EnableEvents
        bCalc = .Calculation
        
        .ScreenUpdating = False
        .Calculation = xlCalculationManual
        .EnableEvents = False

        Set rng = .Union(Rows("13:20016"), Rows("20025:20528"), Rows("20537:20590"))
        rng.EntireRow.Hidden = Not rng.EntireRow.Hidden

        .EnableEvents = bEvents
        .Calculation = bCalc
        .Calculate
        .ScreenUpdating = bSUpd

    End With
End Sub
 
Upvote 0
Hi, many thanks for the help, but unfortunately it is still the same in terms of speed?
 
Upvote 0
You're welcome, but I have no more suggestions regarding your issue.
Perhaps the performance difference has to do with the difference in data on one worksheet and the other.
 
Upvote 0

Forum statistics

Threads
1,215,024
Messages
6,122,729
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top