Ask a question »

Excel - Hide rows with zero value in Multiple sheets

August 2015


Excel - Hide rows with zero value in Multiple sheets




Issue


Please help me in making a macro in the Excelsheet that:
I can hide the entire rows if a cell value or (range of values) has a zero value in multiple sheets??? I mean for example either when I open the file or when I click on control bottom to run the macro.


My case is:
I have one excel file that has 32 sheets for each personnel, and each sheet has a table of 3 columns
(A,B,C) and 26 rows(1-26). 
Column A for text 
Column B for text also 
Column C for Values 

my request is to hide/Unhide the entire row/s depending upon the value in column C and for each sheet of the 32 either by pressing a command or by changing in the values or whatever.

Solution


Objective:
To filter /hide the rows on all sheet for a given value.

Assumptions:
1. The location of the column is same on every sheet
3. Filter needs to be applied on all sheets
3. Sheets are not hidden
4. All Sheets have at least one cell filled

STEPS
1. Read the assumptions
2. Make a back up copy
3. Press ALT + F11 and insert a new module
4. Paste the code and run it

CODE:

Sub HideRows()
Dim Sheet As Object
Dim filterFor As Variant
Dim iFilterCol As Integer

    iFilterCol = 3 'apply filter on 3 col
    
    filterFor = InputBox("Enter the value to be filtered out", "Filter out")
    
    For Each Sheet In Sheets
    
        Sheet.Select
        
        If ActiveSheet.AutoFilterMode Then
            Cells.Select
            Selection.AutoFilter
        End If
    
        Cells.Select
        If ActiveSheet.AutoFilterMode = False Then
            Selection.AutoFilter
        End If
    
        Selection.AutoFilter Field:=iFilterCol, Criteria1:="<>" & filterFor, Operator:=xlAnd
    Next
End Sub

Note


Thanks to rizvisa1 for this tip on the forum.
For unlimited offline reading, you can download this article for free in PDF format:
Excel-hide-rows-with-zero-value-in-multiple-sheets.pdf

See also

In the same category

Published by aakai1056.
This document entitled « Excel - Hide rows with zero value in Multiple sheets » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.