Run 1 Marco on multiple tabs w/1 button

coma08

New Member
Joined
Sep 18, 2014
Messages
2
I'm trying to run the same marco on multiple tabs by clicking on 1 button. Is it possible? thanks

Here's the code:

Sub HideRows()
Rows("17:548").EntireRow.Hidden = False
Dim cell As Range
For Each cell In Range("b17:b548")
If Not IsEmpty(cell) Then
If cell.Value = 0 Then
cell.EntireRow.Hidden = True
End If
End If
Next
End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
not tested
Code:
Sub HideRows()    
    Dim cel As Range
    For Each ws In Worksheets
        With ws
            .Rows("17:548").EntireRow.Hidden = False
            For Each cel In .Range("b17:b548")
                If Not IsEmpty(cel) Then
                    If cel.Value = 0 Then
                        cel.EntireRow.Hidden = True
                    End If
                End If
            Next cel
        End With
    Next ws
End Sub

btw not good practice to use reserved words (like cell) for variable names

PS this will run on all sheets. If you need it to not run on some, then you're going to need another if statement inside the ws for...next loop, but I figure you can handle that
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,397
Messages
6,119,273
Members
448,883
Latest member
fyfe54

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