Slow running code to hide a range of rows based on a cell value, how can I speed it up or fix it.

NoFears

New Member
Joined
Aug 26, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I have tried a couple of different codes to hide rows based on the results of a formula in one cell on that row.

One of them is this.

BeginRow = 58
EndRow = 500
ChkCol = 11

For RowCnt = BeginRow To EndRow
If Cells(RowCnt, ChkCol).Value < 0.1 Then
Cells(RowCnt, ChkCol).EntireRow.Hidden = True
Else
Cells(RowCnt, ChkCol).EntireRow.Hidden = False
End If
Next RowCnt

The above causes a 30 second to 1 minute delay before final results are in.

And I have tried below based on another thread found in these forums, but the results are not accurate.

Range("K57:K5075").AutoFilter Field:=1, Criteria1:="<>"

Basically, in row K I have some cells with a formula that will add up to either a positive or negative number. I want to hide all rows that are 0. I have other rows I don't want to hide with no formula, so I simply typed in a "1" in those row's K cell.

The length of the page can change depending on the job it is used for. SO preferably, I would want something that started at row 58 and goes all the way to the end (again, the end can move, so I guess I would say the rest of the worksheet itself, as long as it does not add any delays).

Any help is greatly appreciated.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Your filter code would be code for none blank cells.

Do you not want to filter cells that are greater than 0?
 
Upvote 0
Your filter code would be code for none blank cells.

Do you not want to filter cells that are greater than 0?
That was my purpose, but I found another way to accomplish this using the last string of text with a minor change. I created a row of hidden cells, with a If statement to get a true or false response. I then plugged in true into the above filter statement and it now works. Though if there is a way to make this work with greater or less than 0 that would be great. I need it to work for both positive and negative numbers. I tried simply adding a 0 after the <> and even tried splitting it up into two commands, one for < and one for >, and the results were off. It would somehow filter out the wrong cells and miss some of the cells with 0 in them. It was not consistent at all. But the true false one is very consistent. Again, if you have a better suggestion, or believe we can make the code work without the added hidden row that would be great.
 
Upvote 0

Forum statistics

Threads
1,214,553
Messages
6,120,182
Members
448,948
Latest member
spamiki

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