Selection.AutoFilter Field represented by "all"

J

JeffFinnan

In a Selection.AutoFilter Field is there a way to have Criteria1 represent
"all"?

For example,

Selection.AutoFilter Field:=4

alone will represent "all"

and

Selection.AutoFilter Field:=4, Criteria1:=Price

will select based on the price.

I have set up a Userform so that "all" could be represented by ">0" in the
string variable Price. But I would preferred to have it represented by "all" in
some form when the textbox is left blank.

I could figure out some code that the ", Criteria1:=Price" is added after
Selection.AutoFilter Field is added but that seems to be going overboard.

Thanks,
Jeff
 
B

Bernie Deitrick

Jeff,

This seems to work fine:

If Price = ">0" Or Price = "" Then
Selection.AutoFilter Field:=4
Else
Selection.AutoFilter Field:=4, Criteria1:=Price
End IF

HTH,
Bernie
Excel MVP
 
J

JeffFinnan

Bernie,

Yeah, I guess I will have to resort to this type of conditional phrasing. I was
hoping that there might be some simpler trick.

Thanks,
Jeff
 

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