Macro running painfully slow.

Dspace

New Member
Joined
Nov 2, 2020
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Good afternoon-
I'm running what I consider to be a fairly simple code. It works but it takes roughly 30 seconds to run which is driving me a little bonkers. I have ala carte pricing from rows 18 to 463. What this codes is saying is if my sales rep enters a value in column H to not hide that row. If the cell is left blank then hide that row. Looking for insight on how to streamline this code so it speeds up the macro. Any insight is appreciated. Thanks

Sub HideAllRows()
'Hides everything without a quantity in column H. Used for all three sales teams as well as Bid Desk when hiding everything if we've added something custom
Unprotect Password:="PW"
Application.ScreenUpdating = True
For Each cell In Range("H18:H463")

cell.EntireRow.Hidden = cell.Value = 0
Next cell
ActiveSheet.Protect Password:="PW", AllowFormattingCells:=True
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
See if this helps any:
Rich (BB code):
Sub HideAllRows()
'Hides everything without a quantity in column H. Used for all three sales teams as well as Bid Desk when hiding everything if we've added something custom
Unprotect Password:="PW"
Application.ScreenUpdating = False
For Each cell In Range("H18:H463")

cell.EntireRow.Hidden = cell.Value = 0
Next cell
Application.ScreenUpdating = True
ActiveSheet.Protect Password:="PW", AllowFormattingCells:=True
End Sub
 
Upvote 0
Solution
You are welcome.

Please note that when marking a post as the solution, please mark the actual thread that contains the solution (not your own post acknowledging that some other post is the solution).

You will notice that once you mark a post as the solution, it also appears at the very top under the original question, so anyone can easily see at quick glance the original question and the solution. So marking any post that does not actually contain the solution would kind of defeat the purpose of that.

I have gone ahead and change the posted solution for you.
 
Upvote 0
You are welcome.

Please note that when marking a post as the solution, please mark the actual thread that contains the solution (not your own post acknowledging that some other post is the solution).

You will notice that once you mark a post as the solution, it also appears at the very top under the original question, so anyone can easily see at quick glance the original question and the solution. So marking any post that does not actually contain the solution would kind of defeat the purpose of that.

I have gone ahead and change the posted solution for you.
Yea, that was dumb on my part. I went back to fix it but you beat me to the punch. Again, thanks for the fix.
 
Upvote 0

Forum statistics

Threads
1,215,633
Messages
6,125,925
Members
449,274
Latest member
mrcsbenson

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