Hide Rows is cell value is 0 or "", calculations are ramping cpu usage

DarkJester89

Board Regular
Joined
Nov 5, 2017
Messages
109
Office Version
  1. 2016
Platform
  1. Windows
Hello, I have the following code but I dont know if its the formatting of the code of there is an easy way to do this code.

It's supposed to hide rows in the range if their value is 0 or "", not unhide it. The code as is works, it just ramps up and takes about 15-20 seconds to calculate by itself.

Is there an more efficient way for this to operate? I have it a macro on a command button, not a worksheet activate or calculate at all times type code. Thank you in advance.

VBA Code:
Sub hiderows()
Dim c As Range
Application.ScreenUpdating = False
For Each c In Range("A3:A73")
    If c.Value = 0 Or c.Value = "" Then
        c.EntireRow.Hidden = True
    Else
        c.EntireRow.Hidden = False
    End If
Next c
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hiding the rows doesn't stop the rows calculating. It would be more efficient to filter the rows rather than loop through them one by one.
 
Upvote 0
It ramps when the macro is running, i didn't know if it was something about this code that's make it do that
 
Upvote 0
Try using Autofilter rather than looping through the rows.
 
Upvote 0
Not sure if its an option here, the calculations in the cell would already be done, would turning off calculations with manualcalc work?

Or maybe closing the loop? It's just a one time hide row, I didn't know it was looping.
 
Upvote 0
This a loop
VBA Code:
For Each c In Range("A3:A73")
try
VBA Code:
Range("A2:A73").AutoFilter 1, "<>0", xlAnd, "<>"
would turning off calculations with manualcalc work
It will speed it up but how much depends on whether the formulas are causing the major issue.
 
Upvote 0
So it worked, but now it's not letting my unhide the rows, even as a push button.
 
Upvote 0
You just turn the filter off in the Data tab.
 
Upvote 0
Is this macro running automatically in the back or do I need to activate it?? hmmm, it's not working, I unhide all columns/rows, and then reapply filters, but it's hiding the new changes that are not 0/"".
 
Upvote 0
Found it, the application screen updating was it, I removed it and it works! :)
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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