Macro very slow... help.

terrycr

New Member
Joined
Jul 14, 2014
Messages
16
I have a spreadsheet that will search through rows to see if there is a match to "C8" (a facility name based on the drop down selection). If so, it should display matching rows only and hide all others. The macro works very slowly. There are 1280 rows. Please advise on how I can shorten this run time.

The workbook can be seen here: WorkBook_Link

The macro is called "HideRowsOtherThanSelected" and initiated by clicking on the facility icon on C8.

VBA Code:
Sub HideRowsOtherThanSelected()
StartRow = 12
EndRow = 1282
ColNum = 12
For i = StartRow To EndRow
If Cells(i, ColNum).Value <> Range("C8").Text Then
Cells(i, ColNum).EntireRow.Hidden = True
Else
Cells(i, ColNum).EntireRow.Hidden = False
End If
Next i

End Sub



Thanks in advance from a newbie.
 

Attachments

  • 2021-06-07.png
    2021-06-07.png
    152.3 KB · Views: 10

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Why not use the autofilter instead.
VBA Code:
Sub HideRowsOtherThanSelected()
   Range("C11:M11").AutoFilter 10, Range("C8").Value
End Sub
 
Upvote 0
Why not use the autofilter instead.
VBA Code:
Sub HideRowsOtherThanSelected()
   Range("C11:M11").AutoFilter 10, Range("C8").Value
End Sub
Thanks for the quick reply. Going this route, my other almost 1000 rows still show (there is a date in the first column).... can this code be modified to hide the other rows too?

Thanks.
 
Upvote 0
You seem to have a table in C1202:D1203 called Table1, convert that to a range.
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,283
Members
449,075
Latest member
staticfluids

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