VBA Code to Hide and Unhide Rows based on dynamically changing data

leebrockney

New Member
Joined
Feb 19, 2008
Messages
18
hello all!! I am trying to build a statement creation tool within Excel. the statement has a few different sections that could range anywhere from a few rows to a couple hundred rows. I am using the below code to review the statement and to hide and unhide any rows that are either unused or were hidden but now have data which means they need unhidden. the problem I am having is that this code takes A LONG TIME to run. probably around 2 minutes each time I kick the code off. While this isn't a long time in the bigger scheme of things, the admin who will be using this has to create dozen and dozens of these reports and 2 minutes each is a big deal when duplicated across many statements.

I am just hoping that maybe there is a more efficient code that wouldnt take so long to run. thanks for any feedback you might have!

Sub Button1_Click()
Dim stmntRange As Range

Application.ScreenUpdating = False
For Each stmntRange In Range("E11:E658")
If (stmntRange.Value = "") Or (stmntRange.Value = "0") Then
stmntRange.EntireRow.Hidden = True
Else
stmntRange.EntireRow.Hidden = False
End If
Next stmntRange
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
When posting vba code in the forum, please use the available code tags. It makes your code much easier to read/debug. Compare the post 10 code, where I have added the tags for you, to the post 9 code. My signature block below has more details. 😊

I also suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,613
Members
449,090
Latest member
vivek chauhan

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