Hide and unhide rows based if total column is zero

mike_ate_a_pie

Board Regular
Joined
Sep 25, 2009
Messages
69
Hi all,

I'm new to VBA and trying to hide all rows in a profit and loss if the total value is zero.

Is it possible to apply this to several spreadsheets at once in the same workbook.

The total column is AS, and the table is C6:AS55

thanks
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
One way that may work for you is to use the Workbook_SheetActivate event.

Paste this into the ThisWorkbook module:
Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    Dim arrSheets()
    Dim lngRowNum As Long
    
    Application.ScreenUpdating = False
    
    arrSheets = Array("Sheet1", "Sheet2", "Sheet3")
    If Not IsError(Application.Match(Sh.Name, arrSheets, 0)) Then
        For lngRowNum = 6 To 55
            Rows(lngRowNum).Hidden = Cells(lngRowNum, 45).Value = 0
        Next lngRowNum
    End If
    
    Application.ScreenUpdating = True
    
End Sub

Change arrSheets to the names of the desired sheets....
 
Upvote 0
cheers this was just what i'm looking for. It works great but does slow my spreadsheet down every time you click on a tab with the macro in. Is there anyway to stop this too?

Thanks
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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