Macro to hide roes in multiple sheets

mike_ate_a_pie

Board Regular
Joined
Sep 25, 2009
Messages
69
Hi all,
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
I have this macro that hides rows when the value is “0”.

<o:p></o:p>
At the moment it’s not running very smoothly and updating quickly, i.e the Application.Sreenupdating isn’t working correctly.

<o:p></o:p>
I would also like to add run this in multiple sheets at the same time. Is this also possible?

<o:p></o:p>
Sub HideRows()
<o:p></o:p>
Dim cell As Range
<o:p></o:p>
Application.ScreenUpdating = False
<o:p></o:p>
For Each cell In Range("AU6:AU100")
cell.EntireRow.Hidden = cell.Value = 0
<o:p></o:p>
Application.ScreenUpdating = True
<o:p></o:p>
Next cell
<o:p></o:p>
End Sub

<o:p></o:p>
<o:p></o:p>
Any help appreciated.

<o:p></o:p>
Thanks in advance,

<o:p></o:p>
Mike
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Mike

Why are you turning on screen updating within the loop?

Putting this after Next cell might help with the first issue.:)
Rich (BB code):
Application.ScreenUpdating = True

 
Upvote 0
i tried this but the way i currently have it you can see the code running which i prefer. When you move the screen updating to below it pauses while the code runs.

thanks
 
Upvote 0
i tried this but the way i currently have it you can see the code running which i prefer. When you move the screen updating to below it pauses while the code runs.

thanks

Just out of curiosity. Why would you turn the screen updating off in the first place, if you want to see the code running?
 
Upvote 0
mike

I'm a little confused - you appear to want to turn off screen updating but you still want to see what's happening?:eek:
 
Upvote 0
Try...

Code:
Option Explicit

Sub HideRows()

    Dim Wksht As Worksheet
    Dim cell As Range
    
    For Each Wksht In Worksheets
        For Each cell In Wksht.Range("AU6:AU100")
            cell.EntireRow.Hidden = cell.Value = 0
        Next cell
    Next Wksht

End Sub
 
Upvote 0
i'm not bothered about the watching the code run but i want this the macro to be manually run. so you can chose to hide rows or view them again. currently i just have the macro above and then a sepearte macro just to unhide the lines.

I would like to run it in around 10 of my 20 worksheets as these are all the same.

Currently i can only run it in one spreadsheet at once and it as before it has the delay.

hope this makes a little more sense... maybe

thanks
 
Upvote 0
Try...

Code:
Option Explicit

Sub HideRows()

    Dim SheetNames As Variant
    Dim sname As Variant
    Dim cell As Range

[COLOR="SeaGreen"]'   Change the sheet names, accordingly[/COLOR]
    SheetNames = Array("Sheet1", "Sheet2", "Sheet3", ..... "Sheet10")
    
    For Each sname In SheetNames
        For Each cell In Sheets(sname).Range("AU6:AU100")
            cell.EntireRow.Hidden = (cell.Value = 0) And Not cell.EntireRow.Hidden
        Next cell
    Next sname

End Sub
 
Upvote 0

Forum statistics

Threads
1,216,460
Messages
6,130,765
Members
449,589
Latest member
Hana2911

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