Hiding rows with zero values

cubiclemonkey

New Member
Joined
Mar 7, 2012
Messages
25
Good Afternoon,

I have a report which has an output that pulls data from another tab in the workbook using the SUMIFs formula based on the Department selected in cell A1. Depending on the Department selected, some of the rows will have zero values. Is there a way to write a macro which will hide the rows with zero values after selecting the Department? I should also add the rows with zero values fluctuate so there is no consistency to it as it depends on which Department is being selected which then fills the rows.

Example is the Cookie Department:

1683741323368.png


And the Donut Department:

1683741413174.png


Thanks,
Ahmed
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
When I try to access the file I get the message "Unauthorized"! Make sure you made the file accessible to anyone with the link.
 
Upvote 0
While trying to come up with a solution I came up with the following, however, the issue is that I need to identify each row to hide and the main data set is much larger:

VBA Code:
Sub hiderows()

Rows("5:20").EntireRow.Hidden = False

x = Range("B1").value

Select Case x

Case 1: Range("11:11,13:13,16:16").EntireRow.Hidden = True
Case 2: Range("7:8,11:11,14:14,16:16").EntireRow.Hidden = True
Case 3: Range("6:6,8:8,11:11,14:14,18:18").EntireRow.Hidden = True
Case 4: Range("6:6,9:9,11:11,13:13,15:15,18:19").EntireRow.Hidden = True

End Select

End Sub
 
Upvote 0
Forget about the question in Post #8. You're working with a dropdown I see.

Does this work for you?
Code:
Sub AAAAA()
Dim ws As Worksheet, lr As Long
lr = Cells(Rows.Count, 6).End(xlUp).Row
Set ws = ActiveSheet
Application.ScreenUpdating = False
    With ws
        .AutoFilterMode = False
        .Range("F6:F" & lr).AutoFilter 1, "<>0"
    End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
The following will work automatically whenever you change the selection in cell A1 of the summary sheet. You'll need to put this code in the sheet code area of the Summary sheet. Right-click the sheet tab name, select View Code, and put the code in the blank area to the right of the screen. I've added an updated file for your perusal with the code already added.

Example_DummyData V2.xlsm

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Range("A1"), Target) Is Nothing Then
        Application.EnableEvents = False
        With Me.Range("F5:F" & Cells(Rows.Count, "F").End(xlUp).Row - 1)
            .AutoFilter 1, "<>0", 1, "<>", 0
        End With
    End If
    Application.EnableEvents = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,329
Messages
6,124,301
Members
449,149
Latest member
mwdbActuary

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