Slow Running Macro

rsmaher

New Member
Joined
Jun 5, 2018
Messages
2
Hi All,

Hope you may be able to help on the below:

I want to make it easier for users to filter the information for what they need using some macro buttons (some struggle with using basic filters); however, it is on a protected and shared workbook so I can't use a VBA filter.

I've created some code to hide the rows that are not required instead.

The macros do work but my problem is that they run slow so I was wondering if I'm missing something or if there is a different type of code that would be more efficient.

Below are a couple of examples.

Example 1:
Code:
Sub ReplenFilter()
    BeginRow = 5
    EndRow = 204
    ChkCol = 7
Range("A5:A204").EntireRow.Hidden = False
Application.ScreenUpdating = False    For RowCnt = BeginRow To EndRow
        If Cells(RowCnt, ChkCol).Value = "Replenishment" Then
            Cells(RowCnt, ChkCol).EntireRow.Hidden = False
        Else
            Cells(RowCnt, ChkCol).EntireRow.Hidden = True
        End If
    Next RowCnt
    
Application.ScreenUpdating = True
    
End Sub

Example 2:
Code:
Sub SortationFilter()
    BeginRow = 5
    EndRow = 204
    ChkCol = 7
    
Application.ScreenUpdating = False
Range("A5:A204").EntireRow.Hidden = False
    For RowCnt = BeginRow To EndRow
        If Cells(RowCnt, ChkCol).Value = "Sortation" Or Cells(RowCnt, ChkCol).Value = "Sorter Run" Then
            Cells(RowCnt, ChkCol).EntireRow.Hidden = False
        Else
            Cells(RowCnt, ChkCol).EntireRow.Hidden = True
        End If
    Next RowCnt
    
Application.ScreenUpdating = True
    
End Sub

Thank you in advance.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
If you have a filter set on the range you are working with, then it will be slowed down by a recalculate being done every time there is a change between false and true. Insert ' Application.Calculation = xlManual' at the beginning and 'Application.Calculation = xlAutomatic' at the end and it will speed ap
 
Upvote 0

Forum statistics

Threads
1,223,730
Messages
6,174,162
Members
452,548
Latest member
Enice Anaelle

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