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
 
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
Thank you for sharing, unfortunately it shows the filter which won't pass with my supervisor.
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
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

Hi Kevin,

Thank you this works except for "Cookies" and "Donuts" which shows row 5 even though it's blank. Another complication is what if I have a second set of data below and there is a space in between the first set of rows and the next set of rows?

Thanks,
Ahmed

1683922071398.png



1683922049827.png
 
Upvote 0
Thank you this works except for "Cookies" and "Donuts" which shows row 5 even though it's blank.
That's because the file you shared (and your original post) has row 5 as a blank row, whereas post #12 has data in that row? Which is correct?

what if I have a second set of data below and there is a space in between the first set of rows and the next set of rows?
If you mean you have your data in 2 (or more) distinct ranges/areas, then please provide a sample of what it would look like as that would require a different approach entirely.
 
Upvote 0
Try this instead
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("F3:F" & Cells(Rows.Count, "F").End(xlUp).Row - 1)
            .AutoFilter 1, "<>0", 1, "<>", 0
        End With
    End If
    Application.EnableEvents = True
End SubPrivate Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Range("A1"), Target) Is Nothing Then
        Application.EnableEvents = False
        With Me.Range("F3: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
Try this instead
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("F3:F" & Cells(Rows.Count, "F").End(xlUp).Row - 1)
            .AutoFilter 1, "<>0", 1, "<>", 0
        End With
    End If
    Application.EnableEvents = True
End SubPrivate Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Range("A1"), Target) Is Nothing Then
        Application.EnableEvents = False
        With Me.Range("F3:F" & Cells(Rows.Count, "F").End(xlUp).Row - 1)
            .AutoFilter 1, "<>0", 1, "<>", 0
        End With
    End If
    Application.EnableEvents = True
End Sub
Thanks Kevin will try. I was able to "trick" excel by applying a flag in another column with your last code but will try this too.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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