Excel Vba Autofilter

mnm1231

New Member
Joined
Mar 31, 2012
Messages
3
Basically i am doing a search, where a user selects an option from several lists and then using autofilters the search is performed on those selected items. The problem that is arising is that i have a "don't know" option in the lists, which means that when this is selected i still want the search to just include all the options for that item, or leave it out of the filter some how.
So if i have 3 fields:

Strength Ductility Luminostiy
hard ductile light
weak brittle dark
dont know don't know dont know

Lets say for the first field, hard is selected, and for the second field ductile is selected and for the third field dont know is selected.

so when searching i can just pass on the text from the first two options but for the 3rd option i dont know what to do, i was thinking of passing an asterisk (*) as the search item but i dont think this will work. the code is

If strengthComboBox.Text = "Dont Know" Then
strength = "*"
Else
strength = strengthComboBox.Text
End If

With Sheet1

.AutoFilterMode = False

With .Range("A1:D1")

.AutoFilter

.AutoFilter Field:=1, Criteria1:=strength
End With
End With
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
add an If/then check before filtering

Code:
With .Range("A1:D1")

.AutoFilter
if strength<>"*" then
    .AutoFilter Field:=1, Criteria1:=strength
endif

or

remove this in red

[COLOR="Red"]If strengthComboBox.Text = "Dont Know" Then
strength = "*"
Else[/COLOR]strength = strengthComboBox.Text
[COLOR="red"]End If[/COLOR]

and use

if strength<>"Dont Know" then
    .AutoFilter Field:=1, Criteria1:=strength
endif
 
Upvote 0

Forum statistics

Threads
1,215,584
Messages
6,125,670
Members
449,248
Latest member
wayneho98

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