Announcement

Collapse
No announcement yet.

VBA: filter with 4 condition

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBA: filter with 4 condition



    Sub Macro6()

    Selection.AutoFilter Field:=13, Criteria1:="=00594", Operator:=xlOr, _
    Criteria2:="=76000"
    End Sub

    from this macro is possible to ADD another 2 criteria

    example
    00594
    76000
    99999
    88888

    tks
    Sal
    1 help 1 pizza
    2 helps 1 pizza 1 caffè
    3 helps 1 pizza 1 caffè 1 mozzarella
    ...

  • #2
    I don't know of a way to have more than two conditions with Autofilter. However you may want to try using the advanced filter, which can have may conditions. For example
    Range("A1:A23").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
    Range("E1:E5"), Unique:=False
    will filter the list in A1 to A23 where E1:E5 has four conditions. E1 has to have the same name as A1.
    Please do not U2U (private message) me directly for questions that should be posted to the forum; any such U2Us will be ignored.

    Comment


    • #3
      Originally posted by Derk
      I don't know of a way to have more than two conditions with Autofilter. However you may want to try using the advanced filter, which can have may conditions. For example
      Range("A1:A23").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
      Range("E1:E5"), Unique:=False
      will filter the list in A1 to A23 where E1:E5 has four conditions. E1 has to have the same name as A1.


      ... please a little sheet with example.
      Tks for all
      Sal
      1 help 1 pizza
      2 helps 1 pizza 1 caffè
      3 helps 1 pizza 1 caffè 1 mozzarella
      ...

      Comment


      • #4
        See the attached for a simple example. The list is in column A and the conditions in column E
        Please do not U2U (private message) me directly for questions that should be posted to the forum; any such U2Us will be ignored.

        Comment


        • #5
          Originally posted by Derk
          See the attached for a simple example. The list is in column A and the conditions in column E


          Tks for all
          Sal
          1 help 1 pizza
          2 helps 1 pizza 1 caffè
          3 helps 1 pizza 1 caffè 1 mozzarella
          ...

          Comment


          • #6
            Little problem (!?)

            the advanced filter start from filetr in m4 and criteria is in z4

            repair for my the macro.
            Tks, very tks.
            Sal
            1 help 1 pizza
            2 helps 1 pizza 1 caffè
            3 helps 1 pizza 1 caffè 1 mozzarella
            ...

            Comment


            • #7
              See the attached. I moved the criteria to column AA for convenience in using the current region to specify your data and to specify the criteria as rows are added or deleted. The buttons for the macro are at the top of column N.
              Please do not U2U (private message) me directly for questions that should be posted to the forum; any such U2Us will be ignored.

              Comment


              • #8
                Originally posted by Derk
                See the attached. I moved the criteria to column AA for convenience in using the current region to specify your data and to specify the criteria as rows are added or deleted. The buttons for the macro are at the top of column N.


                ok! Tks

                Solved?
                Time to Time
                Sal
                1 help 1 pizza
                2 helps 1 pizza 1 caffè
                3 helps 1 pizza 1 caffè 1 mozzarella
                ...

                Comment


                • #9
                  Just for reference, there is a 'cheats' way that I found of using multiple criteria with AutoFilter (AF). However, it isn't very efficient as it involves repeated calls to the AF.

                  If you are interested, AF on your first 2 criteria and set a range equal to the visible cells. Now repeat the process with the next set of criteria and add the visible cells to the previous range using the Union method. With Screenupdating off and relatively small amounts of data this approach is 'workable' - haven't tried it with large amounts of data!
                  Cross-poster? Read this: Cross-posters
                  Struggling to use tags (including Code tags)? : Forum tags

                  Comment


                  • #10
                    Originally posted by Richie(UK)
                    Just for reference, there is a 'cheats' way that I found of using multiple criteria with AutoFilter (AF). However, it isn't very efficient as it involves repeated calls to the AF.

                    If you are interested, AF on your first 2 criteria and set a range equal to the visible cells. Now repeat the process with the next set of criteria and add the visible cells to the previous range using the Union method. With Screenupdating off and relatively small amounts of data this approach is 'workable' - haven't tried it with large amounts of data!
                    a sample sheet please
                    Sal
                    1 help 1 pizza
                    2 helps 1 pizza 1 caffè
                    3 helps 1 pizza 1 caffè 1 mozzarella
                    ...

                    Comment


                    • #11


                      OK, a simple example with 3 criteria.

                      HTH
                      Cross-poster? Read this: Cross-posters
                      Struggling to use tags (including Code tags)? : Forum tags

                      Comment

                      Working...
                      X