Autofilter out Zeros

kylehawkins79

New Member
Joined
May 31, 2019
Messages
7
Im trying to auto filter out zeros on a sheet when a cell is updated. Is there a simple VBA that can do this?


Also If a cell is blank, I want to hide certain rows on a separate sheet. is there another for this?

Thank you
 

Some videos you may like

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Twollaston

Board Regular
Joined
May 24, 2019
Messages
235
Im trying to auto filter out zeros on a sheet when a cell is updated. Is there a simple VBA that can do this?


Also If a cell is blank, I want to hide certain rows on a separate sheet. is there another for this?

Thank you

You can use something like this
ActiveSheet.ListObjects("Table2").Range.AutoFilter Field:=2, Criteria1:="<>" & 0, Operator:=xlFilterValues
Except make sure you use your table name instead of table2, and your field instead of field 2
 

Twollaston

Board Regular
Joined
May 24, 2019
Messages
235
You can use something like this
ActiveSheet.ListObjects("Table2").Range.AutoFilter Field:=2, Criteria1:="<>" & 0, Operator:=xlFilterValues
Except make sure you use your table name instead of table2, and your field instead of field 2

probably something like this is good just put the right sheet name and where it says A1 you can put the starting location of the rows you want to filter
Code:
Sub TurnOFFAutoFilter()


      If Worksheets("Sheet3").Range("A1").AutoFilter Then
                Worksheets("Sheet3").Range("A1").AutoFilter
      End If


      Worksheets("Sheet3").Range("A1").AutoFilter Field:=2, Criteria1:="<>0", Operator:=xlFilterValues


End Sub

The first part will check if there is a filter applied and remove it if needed, and then it filters out the 0s and the blanks to column2
 

Twollaston

Board Regular
Joined
May 24, 2019
Messages
235
Also If a cell is blank, I want to hide certain rows on a separate sheet. is there another for this?

Thank you

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Range("B4").Value = "" Then
        Worksheets("Sheet2").Rows("2").EntireRow.Hidden = True
    Else
        Worksheets("Sheet2").Rows("2").EntireRow.Hidden = False
    End If
End Sub

This will work if you paste it into the worksheet where want to check for the blank value
go to that worksheet and right click the page name, select view code, and paste that code in

For example, paste this into the code on sheet1 and delete the contents of cell b4 then go to sheet 2 and check if row 2 is hidden. And you can change the cell ranges and row details as needed
 
Last edited:

kylehawkins79

New Member
Joined
May 31, 2019
Messages
7
Im a novice at this so forgive me. If I need a single column (AD5) to auto update on Sheet A2 Checklist to not include zeros would I use the same VBA? I tried that one and it didnt work. Thanks again
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,122,935
Messages
5,598,945
Members
414,268
Latest member
bluebandersnatch

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
Top