auto filter Vba

3

I am developing a macro to perform filters using VBA, however in some columns, I have to uncheck some values, for example:

  • Column
  • Paulo
  • Fernanda
  • Carla
  • Lais
  • Renata

I want everything that is different from Paulo, Fernanda and Renata. How can I do this?

I created a macro that works with two values, if I put one only an error occurs, the code below follows:

c = 1
      Do While c <= coluna
        If MyRange = Cells(1, c) Then
            filtrocomp = InputBox("Qual o operador de comparação?" & vbCrLf & "Ex: <,<=,=,>,>=,<>", "Comparação_MAF")
            filtro = InputBox("Qual o filtro de " & MyRange & " Deseja aplicar?", "Comparação_MAF")
            If filtrocomp <> "" Or filtro <> "" Then
                filtrosArray() = Split(filtro, ",")
                Val (filtrosArray(0))
                Cells(1, c).Select
                Selection.AutoFilter Field:=c, Criteria1:=filtrocomp & filtrosArray(0), Operator:=xlAnd, _
                Criteria2:=filtrocomp & filtrosArray(1)
                Exit Do
            Else
                MsgBox "Nenhum filtro foi realizado!!", vbInformation, "Comparação_MAF"
            End If
        End If
        c = c + 1
      Loop
    
asked by anonymous 26.06.2015 / 19:46

2 answers

0

I have modified the code, it should work for a filter.

I also removed Val (filtrosArray(0)) , did nothing in your code.

    c = 1
          Do While c <= coluna
            If MyRange = Cells(1, c) Then
                filtrocomp = InputBox("Qual o operador de comparação?" & vbCrLf & "Ex: <,<=,=,>,>=,<>", "Comparação_MAF")
                filtro = InputBox("Qual o filtro de " & MyRange & " Deseja aplicar?", "Comparação_MAF")
                If filtrocomp <> "" Or filtro <> "" Then
                    filtrosArray() = Split(filtro, ",")

                    Cells(1, c).Select
                    if ubound(filtrosArray)=1 then
                      Selection.AutoFilter Field:=c, Criteria1:=filtrocomp & filtrosArray(0), Operator:=xlAnd, _
                    Criteria2:=filtrocomp & filtrosArray(1)
                    else
                      Selection.AutoFilter Field:=c, Criteria1:=filtrocomp & filtrosArray(0)
                    End if                    


                  Exit Do
                Else
                    MsgBox "Nenhum filtro foi realizado!!", vbInformation, "Comparação_MAF"
                End If
            End If
            c = c + 1
          Loop
    
26.06.2015 / 20:00
0

If you have filter groups you can create a matching table and an extra column to filter. now depends on complexity. example state column, column_aux Home, Filter type 1 section 1, Filter type 2 section 2, Filter type 2 section 3, Filter type 2 section 4, Filter type 2 Conclusion, Type 1 filter End, Type 1 filter

On the other hand, we could also make filters with wildcards of type "START_ ", which returns all those starting with "START_", or " _SLB_ *" all that have the word " in> SLB "either at the beginning, middle or end.

It's a different approach but can even help the user

    
22.06.2017 / 12:50