Macro very slow... help.

terrycr

New Member
Joined
Jul 14, 2014
Messages
9
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: 8

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
68,339
Office Version
  1. 365
Platform
  1. Windows
Why not use the autofilter instead.
VBA Code:
Sub HideRowsOtherThanSelected()
   Range("C11:M11").AutoFilter 10, Range("C8").Value
End Sub
 

terrycr

New Member
Joined
Jul 14, 2014
Messages
9
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
68,339
Office Version
  1. 365
Platform
  1. Windows
You seem to have a table in C1202:D1203 called Table1, convert that to a range.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,579
Messages
5,770,967
Members
425,653
Latest member
UNSING

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
Top