Hide function taking a long time

sweeneytime

Board Regular
Joined
Aug 23, 2010
Messages
183
Hi guys,

Looking for some help please,

I have a report, 500 lines long, one column says yes or no, I loop through the column to the last cell. If it says no, then hide that row.

The below code works, but it takes about 2 or 3 minutes to run, would anybody know how I could shorten the running time please?

I took off screen updating but it didn't reduce the run time by much. And that was my "bright' idea! haha


Thanks,
Sweeneytime
HTML:
Sub hide()
    
    Application.Calculation = xlManual
    Application.ScreenUpdating = False
   
    Dim LR As Long
    Dim myCell As Range
    Dim myRng As Range
    
    'Find last cell in AC
    LR = Range("AC" & Rows.Count).End(xlUp).Row
    
    'Set range
    Set myRng = Range("AC4:AC" & LR)
    
    'Loop through range
    For Each myCell In myRng.Cells
       
    ' If cell = No then hide row
    Select Case myCell.Value
        Case "No"
            myCell.Activate
            myCell.EntireRow.Select
            Selection.EntireRow.Hidden = True
                                  
        Case Else
                     
        
    End Select
    Next myCell
    
    
    Application.ScreenUpdating = True
    Application.Calculation = xlAutomatic
    
End Sub
 

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.
Code:
Sub HideRows()
    
    Application.Calculation = xlManual
    Application.ScreenUpdating = False
   
    Dim LR As Long
    Dim myRng As Range
    
    'Find last cell in AC
    LR = Range("AC" & Rows.Count).End(xlUp).Row
    
    'Set range
    Set myRng = Range("AC4:AC" & LR)
    
    ' Reset autofilter, if exists.
    With ActiveSheet
        If .AutoFilterMode Then .AutoFilter.Range.AutoFilter
    End With
    
    myRng.AutoFilter Field:=1, Criteria1:="No"
    
    On Error Resume Next
    myRng.SpecialCells(xlCellTypeVisible).EntireRow.Hidden = True
    
    If Err.Number <> 0 Then MsgBox "No matches found"
    
    ' Remove autofilter
    With ActiveSheet
        If .AutoFilterMode Then .AutoFilter.Range.AutoFilter
    End With
    
    Application.ScreenUpdating = True
    Application.Calculation = xlAutomatic
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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