Auto Filter where range includes cells with a value of ""

Reddog94

Board Regular
Joined
Dec 20, 2011
Messages
52
I am using an auto filter criteria range, where the cells reference filter selections input on a different tab. For example, the cells in the criteria range have a formula similar to this:

=if(Sheet1!A1="","",Sheet1!A1)

However, if only 1 of the 4 input selections are chosen (which is often the case), when I run the auto-filter all lines are hidden. For example, I want to see all lines of data for the month of January:

Filter on Department: <blank>
Filter on Year: <blank>
Filter on Month: JAN
Filter on Description: <blank>

Unless there is a selection for all 4, all lines are hidden. I think it is because it is looking to filter on cells that have "", which of course nothing in the filter range has. Is there another way to either write the if formula, or a way to tell the auto-filter to ignore blank cells (that aren't really 'blank", because they have the "" in them)?

If I remove the formula in the cells that have no selection, the auto-filter works fine but that kind of defeats the purpose. The code I'm using is:

Code:
Sub AutoFilter2()
    Dim rngCritLabor As Range
    Dim rngFilterLabor As Range
    
    With Sheets("Labor")
        Set rngCritLabor = .Range("Filter_Crit_Labor")
        Set rngFilterLabor = .Range("Filter_Data_Labor")
    End With
    
    rngFilterLabor.AdvancedFilter _
        Action:=xlFilterInPlace, _
        criteriarange:=rngCritLabor
                    
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Why don't you have it return a zero, and hide the zero in options? Would that work?
 
Upvote 0
That would probably work, except I don't know how to hide the 0 in options...can you tell me please?
 
Upvote 0
I don't know ... In 2010, go to File>Options>Advanced and under the Display options for this worksheet group, uncheck Show a zero in cells that have a zero value.
Or you could format the cells as Accounting (and select zero decimal places, if you want).
 
Upvote 0
I thought you mean options in the auto-filter. Unfortunately shows zeros is already unchecked and the format doesn't seem to impact the auto-filter issue. I did narrow it down to being related to data lines in the filter range that have blanks or zeros. Still not sure how to resolve though. Thanks for your suggestions.
 
Upvote 0
You need to tweak your formula so that it returns all records in the respective column for that criteria value. If the column contains text, then rather than ="", your formula needs to return ="=*". If numerics (eg Year) then perhaps =">0"
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,305
Members
449,079
Latest member
juggernaut24

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