xl2002 - AutoFilter from Criteria from Other Sheet...

T

Trevor Williams

I am trying to apply an AutoFilter to records on "Sheet 2" using criteria
chosen from 7 lists on "Sheet 1"

The filtering works if each criteria contains a value, but if one is left
blank no records are shown.

I have tried adding the value "(all)" as a default into the lists on Sheet 1
but that doesn't work either.

How can I skip 'blank' entries when filtering using code? (current code
below)

Thanks

Trevor

Sub FilterResult()

myFilter = Array("ctDescription", "ctMarket", "ctPOB", "ctChannel", _
"ctCategory", "ctQuality", "ctCompetition")

For i = 0 To 6
x = myFilter(i)
Selection.AutoFilter Field:=i + 1, Criteria1:=Range(x), _
VisibleDropDown:=False
Next i

End Sub
 
T

Tom Ogilvy

Sub FilterResult()

myFilter = Array("ctDescription", "ctMarket", "ctPOB", "ctChannel", _
"ctCategory", "ctQuality", "ctCompetition")

For i = 0 To 6
x = myFilter(i)
set rng = Range(x)
if rng.Value <> "" then
Selection.AutoFilter Field:=i + 1, Criteria1:=Range(x), _
VisibleDropDown:=False
else
Selection.AutoFilter Field:=i + 1, _
VisibleDropDown:=False
end if
Next i

End Sub
 
T

Trevor Williams

Excellent, Thanks Tom

Trevor

Tom Ogilvy said:
Sub FilterResult()

myFilter = Array("ctDescription", "ctMarket", "ctPOB", "ctChannel", _
"ctCategory", "ctQuality", "ctCompetition")

For i = 0 To 6
x = myFilter(i)
set rng = Range(x)
if rng.Value <> "" then
Selection.AutoFilter Field:=i + 1, Criteria1:=Range(x), _
VisibleDropDown:=False
else
Selection.AutoFilter Field:=i + 1, _
VisibleDropDown:=False
end if
Next i

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top