VBA hiding rows seems slow any ideas?

KirnonBhale

New Member
Joined
Jul 25, 2019
Messages
11
Code:
[FONT=Calibri][SIZE=3][COLOR=#000000]Sub HideRowsOnSheet()[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Dim i As Long[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Application.ScreenUpdating = False[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]For i = 10 To 122[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]    IfActiveSheet.Cells(i, "D") = 0 And ActiveSheet.Cells(i, "D")<> "" Then ActiveSheet.Rows(i).Hidden = True[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Next i[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Application.ScreenUpdating = True[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]End Sub[/COLOR][/SIZE][/FONT]

The above code does the job but it takes over 2min. to finish running. This seems especially slow as I could accomplish the task that the code is performing more quickly. Is there a quicker way to accomplish the task of hiding rows with a 0 in column D?

I have a similar code for operation over 8 Tabs but it takes 20 min + to fully run which is in my mind excessive.

Any help making this run quicker would be greatly appreciated.
 
Its just practice. Im self taught and by using excel, reading around and picking up ideas you learn. In this case you just need to understand that accessing the worksheet and hiding rows is expensive in terms of time so this just gives you a way to do that as little as possible.

I'm self-taught too - just obviously haven't learned as well as you have. I'm going to be cannibalising this for all sorts in the future I think.
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,224,828
Messages
6,181,213
Members
453,024
Latest member
Wingit77

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