1

I'm trying to get my code to filter out multiple values so I can see any employee that may remain on the list. It works wonderfully when I enter one name (i.e. "Smith"), as it does take the name out of my list. However, when I try to enter another name (such as "White"), "Smith" comes back on the list while "White" is filtered out. I'd like BOTH names to be filtered out, as well as any other names I may need out.

Sub Driver()

    Dim Driver As String

    uiDriver = Application.InputBox("Filter out Driver", Type:=2)
    If uiDriver = "False" Then Exit Sub: Rem Cancel pressed

    Range("A1").Select
    Selection.AutoFilter
    Selection.AutoFilter field:=2, Criteria1:="<>*" & uiDriver & "*", Operator:=xlAnd

End Sub

Any tips would be greatly appreciated, thanks!

Community
  • 1
  • 1
Bri
  • 11
  • 3
  • Upvoted just because OMG a `Rem` comment! I just saw my life flash before my eyes, memories of C-64 BASIC 2.0 listings scrolling on a 14-inch TV, white on a blue background... glad to see you're not numbering your code lines. Now that said, [avoid Select and Activate](https://stackoverflow.com/q/10714251/1188513), and [NEWLINE] being the instruction separator token in VBA, that 2nd `AutoFilter` call wants an underscore / line continuation token after the comma (i.e. should read `& "*", _`), otherwise the compiler can't parse that `Operator:=xlAnd` part, and the trailing comma isn't valid. – Mathieu Guindon Jul 06 '17 at 16:41
  • Modern VB* code uses a single quote for comments. `' cancel was pressed` – Mathieu Guindon Jul 06 '17 at 16:42
  • 1
    Also you're declaring `Driver` but assigning (and using) `uiDriver`. Specify `Option Explicit` at the top of the module, so that such typos prevent your code from happily compiling and running nonsense. – Mathieu Guindon Jul 06 '17 at 16:44
  • @Mat'sMug cracked a smile there (y) – jmdon Jul 06 '17 at 16:53

0 Answers0