Use Variant Variable In Filter Condition In VBA

  • I am wanting to use VBA to filter a worksheet. I am reading the userID's from the worksheet like this

    Code
    Dim userID As Variant
    Dim uID As Variant
    userID = Sheets("Data").Range("B2:B101").Value


    Then I try to do the below, to use VBA to filter it filters out all rows acting as if the value does not exist?

    Code
    For Each uID In userID
        Sheets("Data").Range("$A$1:$BV$153").AutoFilter Field:=2, Criteria1:=userID
    Next
  • You are setting userid to a range of cells, it needs to be set to one cell. I'm not sure why you are looping but maybe you mean


    Code
    For Each uID In userID     Sheets("Data").Range("$A$1:$BV$153").AutoFilter Field:=2, Criteria1:=uID Next

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!