Olá pessoal!
Necessito novamente de vossa ajuda!
É a mesma planilha, porem ela creceu e ficou mais robusta.
Problema atual: Adequar a planilha para novos critérios, havendo a possibilidade de múltiplos critérios para a pesquisa.
Agora temos 9 critérios:
A2, B2, C2, D2, E2, G2, H2, I2, J2
O código atual engloba apenas os critérios A2, B2, C2, D2 e E2, conforme código abaixo:
Sub NovaVersao()
Dim LR As Long
Rows(6).Resize(100).Delete
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" Then AleVBA = 1
If Range("a2") = "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" Then AleVBA = 2
If Range("a2") = "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") = "" Then AleVBA = 3
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") = "" Then AleVBA = 4
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") <> "" Then AleVBA = 5
If Range("a2") <> "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" Then AleVBA = 6
If Range("a2") <> "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") = "" Then AleVBA = 7
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") = "" Then AleVBA = 8
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") <> "" Then AleVBA = 9
If Range("a2") = "" And Range("b2") <> "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") = "" Then AleVBA = 10
If Range("a2") = "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") = "" Then AleVBA = 11
If Range("a2") = "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") = "" And Range("e2") <> "" Then AleVBA = 12
If Range("a2") = "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") <> "" And Range("e2") = "" Then AleVBA = 13
If Range("a2") = "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") <> "" Then AleVBA = 14
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") <> "" Then AleVBA = 15
If Range("a2") <> "" And Range("b2") <> "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") = "" Then AleVBA = 16
If Range("a2") <> "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") = "" Then AleVBA = 17
If Range("a2") <> "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") = "" And Range("e2") <> "" Then AleVBA = 18
If Range("a2") <> "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") <> "" And Range("e2") = "" Then AleVBA = 19
If Range("a2") <> "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") <> "" Then AleVBA = 20
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") <> "" Then AleVBA = 21
If Range("a2") = "" And Range("b2") <> "" And Range("c2") <> "" And Range("d2") <> "" And Range("e2") = "" Then AleVBA = 22
If Range("a2") = "" And Range("b2") <> "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") <> "" Then AleVBA = 23
If Range("a2") = "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") <> "" Then AleVBA = 24
If Range("a2") = "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") <> "" And Range("e2") <> "" Then AleVBA = 25
If Range("a2") <> "" And Range("b2") <> "" And Range("c2") <> "" And Range("d2") <> "" And Range("e2") = "" Then AleVBA = 26
If Range("a2") <> "" And Range("b2") <> "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") <> "" Then AleVBA = 27
If Range("a2") <> "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") <> "" Then AleVBA = 28
If Range("a2") <> "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") <> "" And Range("e2") <> "" Then AleVBA = 29
If Range("a2") = "" And Range("b2") <> "" And Range("c2") <> "" And Range("d2") <> "" And Range("e2") <> "" Then AleVBA = 30
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("g2") <> "" Then AleVBA = 31
If Range("a2") <> "" And Range("b2") <> "" And Range("c2") <> "" And Range("d2") <> "" And Range("e2") <> "" Then fjpVBA = 32
Select Case AleVBA
Case 1
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=1, Criteria1:=Range("a2")
.Copy Range("a6")
.AutoFilter
End With
Case 2
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=4, Criteria1:=Range("b2")
.Copy Range("a6")
.AutoFilter
End With
Case 3
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=8, Criteria1:=Range("c2")
.Copy Range("a6")
.AutoFilter
End With
Case 4
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=21, Criteria1:=Range("d2")
.Copy Range("a6")
.AutoFilter
End With
Case 5
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=24, Criteria1:=">=" & Format(Range("e2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat), Operator:=xlAnd, Criteria2:="<=" & Format(Range("f2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat)
.Copy Range("a6")
.AutoFilter
End With
Case 6
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=1, Criteria1:=Range("a2")
.AutoFilter Field:=4, Criteria1:=Range("b2")
.Copy Range("a6")
.AutoFilter
End With
Case 7
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=1, Criteria1:=Range("a2")
.AutoFilter Field:=8, Criteria1:=Range("c2")
.Copy Range("a6")
.AutoFilter
End With
Case 8
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=1, Criteria1:=Range("a2")
.AutoFilter Field:=21, Criteria1:=Range("d2")
.Copy Range("a6")
.AutoFilter
End With
Case 9
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=1, Criteria1:=Range("a2")
.AutoFilter Field:=24, Criteria1:=">=" & Format(Range("e2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat), Operator:=xlAnd, Criteria2:="<=" & Format(Range("f2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat)
.Copy Range("a6")
.AutoFilter
End With
Case 10
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=4, Criteria1:=Range("b2")
.AutoFilter Field:=8, Criteria1:=Range("c2")
.Copy Range("a6")
.AutoFilter
End With
Case 11
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=4, Criteria1:=Range("b2")
.AutoFilter Field:=21, Criteria1:=Range("d2")
.Copy Range("a6")
.AutoFilter
End With
Case 12
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=4, Criteria1:=Range("b2")
.AutoFilter Field:=24, Criteria1:=">=" & Format(Range("e2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat), Operator:=xlAnd, Criteria2:="<=" & Format(Range("f2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat)
.Copy Range("a6")
.AutoFilter
End With
Case 13
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=8, Criteria1:=Range("c2")
.AutoFilter Field:=21, Criteria1:=Range("d2")
.Copy Range("a6")
.AutoFilter
End With
Case 14
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=8, Criteria1:=Range("c2")
.AutoFilter Field:=24, Criteria1:=">=" & Format(Range("e2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat), Operator:=xlAnd, Criteria2:="<=" & Format(Range("f2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat)
.Copy Range("a6")
.AutoFilter
End With
Case 15
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=21, Criteria1:=Range("d2")
.AutoFilter Field:=24, Criteria1:=">=" & Format(Range("e2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat), Operator:=xlAnd, Criteria2:="<=" & Format(Range("f2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat)
.Copy Range("a6")
.AutoFilter
End With
Case 16
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=1, Criteria1:=Range("a2")
.AutoFilter Field:=4, Criteria1:=Range("b2")
.AutoFilter Field:=8, Criteria1:=Range("c2")
.Copy Range("a6")
.AutoFilter
End With
Case 17
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=1, Criteria1:=Range("a2")
.AutoFilter Field:=4, Criteria1:=Range("b2")
.AutoFilter Field:=21, Criteria1:=Range("d2")
.Copy Range("a6")
.AutoFilter
End With
Case 18
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=1, Criteria1:=Range("a2")
.AutoFilter Field:=4, Criteria1:=Range("b2")
.AutoFilter Field:=24, Criteria1:=">=" & Format(Range("e2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat), Operator:=xlAnd, Criteria2:="<=" & Format(Range("f2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat)
.Copy Range("a6")
.AutoFilter
End With
Case 19
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=1, Criteria1:=Range("a2")
.AutoFilter Field:=8, Criteria1:=Range("c2")
.AutoFilter Field:=21, Criteria1:=Range("d2")
.Copy Range("a6")
.AutoFilter
End With
Case 20
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=1, Criteria1:=Range("a2")
.AutoFilter Field:=8, Criteria1:=Range("c2")
.AutoFilter Field:=24, Criteria1:=">=" & Format(Range("e2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat), Operator:=xlAnd, Criteria2:="<=" & Format(Range("f2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat)
.Copy Range("a6")
.AutoFilter
End With
Case 21
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=1, Criteria1:=Range("a2")
.AutoFilter Field:=21, Criteria1:=Range("d2")
.AutoFilter Field:=24, Criteria1:=">=" & Format(Range("e2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat), Operator:=xlAnd, Criteria2:="<=" & Format(Range("f2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat)
.Copy Range("a6")
.AutoFilter
End With
Case 22
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=4, Criteria1:=Range("b2")
.AutoFilter Field:=8, Criteria1:=Range("c2")
.AutoFilter Field:=21, Criteria1:=Range("d2")
.Copy Range("a6")
.AutoFilter
End With
Case 23
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=4, Criteria1:=Range("b2")
.AutoFilter Field:=8, Criteria1:=Range("c2")
.AutoFilter Field:=24, Criteria1:=">=" & Format(Range("e2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat), Operator:=xlAnd, Criteria2:="<=" & Format(Range("f2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat)
.Copy Range("a6")
.AutoFilter
End With
Case 24
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=4, Criteria1:=Range("b2")
.AutoFilter Field:=21, Criteria1:=Range("d2")
.AutoFilter Field:=24, Criteria1:=">=" & Format(Range("e2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat), Operator:=xlAnd, Criteria2:="<=" & Format(Range("f2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat)
.Copy Range("a6")
.AutoFilter
End With
Case 25
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=8, Criteria1:=Range("c2")
.AutoFilter Field:=21, Criteria1:=Range("d2")
.AutoFilter Field:=24, Criteria1:=">=" & Format(Range("e2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat), Operator:=xlAnd, Criteria2:="<=" & Format(Range("f2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat)
.Copy Range("a6")
.AutoFilter
End With
Case 26
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=1, Criteria1:=Range("a2")
.AutoFilter Field:=4, Criteria1:=Range("b2")
.AutoFilter Field:=8, Criteria1:=Range("c2")
.AutoFilter Field:=21, Criteria1:=Range("d2")
.Copy Range("a6")
.AutoFilter
End With
Case 27
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=1, Criteria1:=Range("a2")
.AutoFilter Field:=4, Criteria1:=Range("b2")
.AutoFilter Field:=8, Criteria1:=Range("c2")
.AutoFilter Field:=24, Criteria1:=">=" & Format(Range("e2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat), Operator:=xlAnd, Criteria2:="<=" & Format(Range("f2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat)
.Copy Range("a6")
.AutoFilter
End With
Case 28
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=1, Criteria1:=Range("a2")
.AutoFilter Field:=4, Criteria1:=Range("b2")
.AutoFilter Field:=21, Criteria1:=Range("d2")
.AutoFilter Field:=24, Criteria1:=">=" & Format(Range("e2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat), Operator:=xlAnd, Criteria2:="<=" & Format(Range("f2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat)
.Copy Range("a6")
.AutoFilter
End With
Case 29
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=1, Criteria1:=Range("a2")
.AutoFilter Field:=8, Criteria1:=Range("c2")
.AutoFilter Field:=21, Criteria1:=Range("d2")
.AutoFilter Field:=24, Criteria1:=">=" & Format(Range("e2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat), Operator:=xlAnd, Criteria2:="<=" & Format(Range("f2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat)
.Copy Range("a6")
.AutoFilter
End With
Case 30
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=4, Criteria1:=Range("b2")
.AutoFilter Field:=8, Criteria1:=Range("c2")
.AutoFilter Field:=21, Criteria1:=Range("d2")
.AutoFilter Field:=24, Criteria1:=">=" & Format(Range("e2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat), Operator:=xlAnd, Criteria2:="<=" & Format(Range("f2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat)
.Copy Range("a6")
.AutoFilter
End With
Case 31
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=35, Criteria1:=Range("g2")
.Copy Range("a6")
.AutoFilter
End With
Case Else
With Sheets("MOVCAIXA").UsedRange
.AutoFilter Field:=1, Criteria1:=Range("a2")
.AutoFilter Field:=4, Criteria1:=Range("b2")
.AutoFilter Field:=8, Criteria1:=Range("c2")
.AutoFilter Field:=21, Criteria1:=Range("d2")
.AutoFilter Field:=24, Criteria1:=">=" & Format(Range("e2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat), Operator:=xlAnd, Criteria2:="<=" & Format(Range("f2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat)
.Copy Range("a6")
.AutoFilter
End With
End Select
End Sub
Tentei adequar o código acima para os novos critérios usando a mesma lógica, porem o código ficaria uma aberração ai parei para achar outra solução. Segue abaixo o esboço de como estava ficando o "monstro":
(Deletei boa parte, pois o limite de caracteres permitidos é 60000)
Sub NovaVersao()
Dim LR As Long
Rows(6).Resize(100).Delete
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 1
If Range("a2") = "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 2
If Range("a2") = "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 3
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 4
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") <> "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 5
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") <> "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") <> "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") <> "" And Range("J2") = "" Then AleVBA =
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") <> "" Then AleVBA =
If Range("a2") <> "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 6
If Range("a2") <> "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 7
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 8
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") <> "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 9
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") <> "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") <> "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") <> "" And Range("J2") = "" Then AleVBA =
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") <> "" Then AleVBA =
If Range("a2") = "" And Range("b2") <> "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 10
If Range("a2") = "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 11
If Range("a2") = "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") = "" And Range("e2") <> "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 12
If Range("a2") = "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") <> "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") = "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") <> "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") = "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") <> "" And Range("J2") = "" Then AleVBA =
If Range("a2") = "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") <> "" Then AleVBA =
If Range("a2") = "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") <> "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 13
If Range("a2") = "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") <> "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 14
If Range("a2") = "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") = "" And Range("G2") <> "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") = "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") <> "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") = "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") <> "" And Range("J2") = "" Then AleVBA =
If Range("a2") = "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") <> "" Then AleVBA =
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") <> "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 15
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") = "" And Range("G2") <> "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") = "" And Range("G2") = "" And Range("H2") <> "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") <> "" And Range("J2") = "" Then AleVBA =
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") <> "" Then AleVBA =
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") <> "" And Range("G2") <> "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") <> "" And Range("G2") = "" And Range("H2") <> "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") <> "" And Range("G2") = "" And Range("H2") = "" And Range("I2") <> "" And Range("J2") = "" Then AleVBA =
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") <> "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") <> "" Then AleVBA =
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") <> "" And Range("H2") <> "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") <> "" And Range("H2") = "" And Range("I2") <> "" And Range("J2") = "" Then AleVBA =
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") <> "" And Range("H2") = "" And Range("I2") = "" And Range("J2") <> "" Then AleVBA =
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") <> "" And Range("I2") <> "" And Range("J2") = "" Then AleVBA =
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") <> "" And Range("I2") = "" And Range("J2") <> "" Then AleVBA =
If Range("a2") = "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") <> "" And Range("J2") <> "" Then AleVBA =
If Range("a2") <> "" And Range("b2") <> "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 16
If Range("a2") <> "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 17
If Range("a2") <> "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") = "" And Range("e2") <> "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 18
If Range("a2") <> "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") <> "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") <> "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") <> "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") <> "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") <> "" And Range("J2") = "" Then AleVBA =
If Range("a2") <> "" And Range("b2") <> "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") <> "" Then AleVBA =
If Range("a2") <> "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") <> "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 19
If Range("a2") <> "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") <> "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 20
If Range("a2") <> "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") = "" And Range("G2") <> "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") <> "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") <> "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") <> "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") <> "" And Range("J2") = "" Then AleVBA =
If Range("a2") <> "" And Range("b2") = "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") <> "" Then AleVBA =
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") <> "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 21
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") = "" And Range("G2") <> "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") = "" And Range("G2") = "" And Range("H2") <> "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") <> "" And Range("J2") = "" Then AleVBA =
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") <> "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") <> "" Then AleVBA =
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") <> "" And Range("G2") <> "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") <> "" And Range("G2") = "" And Range("H2") <> "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") <> "" And Range("G2") = "" And Range("H2") = "" And Range("I2") <> "" And Range("J2") = "" Then AleVBA =
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") <> "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") <> "" Then AleVBA =
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") <> "" And Range("H2") <> "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") <> "" And Range("H2") = "" And Range("I2") <> "" And Range("J2") = "" Then AleVBA =
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") <> "" And Range("H2") = "" And Range("I2") = "" And Range("J2") <> "" Then AleVBA =
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") <> "" And Range("I2") <> "" And Range("J2") = "" Then AleVBA =
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") <> "" And Range("I2") = "" And Range("J2") <> "" Then AleVBA =
If Range("a2") <> "" And Range("b2") = "" And Range("c2") = "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") <> "" And Range("J2") <> "" Then AleVBA =
If Range("a2") = "" And Range("b2") <> "" And Range("c2") <> "" And Range("d2") <> "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 22
If Range("a2") = "" And Range("b2") <> "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") <> "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA = 23
If Range("a2") = "" And Range("b2") <> "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") = "" And Range("G2") <> "" And Range("H2") = "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") = "" And Range("b2") <> "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") <> "" And Range("I2") = "" And Range("J2") = "" Then AleVBA =
If Range("a2") = "" And Range("b2") <> "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") <> "" And Range("J2") = "" Then AleVBA =
If Range("a2") = "" And Range("b2") <> "" And Range("c2") <> "" And Range("d2") = "" And Range("e2") = "" And Range("G2") = "" And Range("H2") = "" And Range("I2") = "" And Range("J2") <> "" Then AleVBA =
Assim tentei adequar o código disponibilizado pelo Reinaldo para o problema atual, inicialmente o código está assim:
Sub FiltroAle()
Dim lastColum, lastRow As Long
lastRow = Sheets("MOVCAIXA").Cells(Cells.Rows.Count, "A").End(xlUp).Row
lastColum = Sheets("MOVCAIXA").Cells(lastRow, Cells.Columns.Count).End(xlToLeft).Address
Sheets("Lancamento").Rows(6).Resize(1000).Delete
If Range("a2").Value <> "" Then
d1 = Range("a2").Value
Else
d1 = "<>""" '">0"
End If
If Range("b2").Value <> "" Then
d2 = Range("b2").Value
Else
d2 = "<>""" '">0"
End If
If Range("c2").Value <> "" Then
d3 = Range("c2").Value
Else
d3 = "<>""" '">0"
End If
If Range("d2").Value <> "" Then
d4 = Range("d2").Value
Else
d4 = "<>""" '">0"
End If
If Range("e2").Value <> "" Then
d5 = ">=" & Format(Range("e2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat)
d41 = "<=" & Format(Range("f2").Value, Sheets("MOVCAIXA").Range("X2").NumberFormat)
Else
d5 = "<>""" '">0"
End If
If Range("g2").Value <> "" Then
d6 = Range("g2").Value
Else
d6 = "<>""" '">0"
End If
If Range("h2").Value <> "" Then
d7 = Range("h2").Value
Else
d7 = "<>""" '">0"
End If
If Range("i2").Value <> "" Then
d8 = Range("i2").Value
Else
d8 = "<>""" '">0"
End If
If Range("j2").Value <> "" Then
d9 = Range("j2").Value
Else
d9 = "<>""" '">0"
End If
With Sheets("MOVCAIXA").Range("A1:" & lastColum) 'UsedRange
.AutoFilter Field:=1, Criteria1:=d1 'Range("a2")
.AutoFilter Field:=4, Criteria1:=d2 'Range("b2")
.AutoFilter Field:=8, Criteria1:=d3 'Range("c2")
.AutoFilter Field:=25, Criteria1:=d4 'Range("d2")
.AutoFilter Field:=31, Criteria1:=d5 & d41 'Range("e2")
.AutoFilter Field:=39, Criteria1:=d6 'Range("g2")
.AutoFilter Field:=10, Criteria1:=d7 'Range("h2")
.AutoFilter Field:=11, Criteria1:=d8 'Range("i2")
.AutoFilter Field:=41, Criteria1:=d9 'Range("j2")
.Copy Range("a6")
.AutoFilter
End With
End Sub
Porem ele busca apenas o critério A2, nenhum outro funciona.
Para finalizar, segue o código original postado pelo Reinaldo e uma planilha de modelo anexa:
Sub FiltroAle()
Dim lastColum, lastRow As Long
lastRow = Sheets("A2002").Cells(Cells.Rows.Count, "A").End(xlUp).Row
lastColum = Sheets("A2002").Cells(lastRow, Cells.Columns.Count).End(xlToLeft).Address
Sheets("Lancamento").Rows(6).Resize(1000).Delete
If Range("a2").Value <> "" Then
d1 = Range("a2").Value
Else
d1 = "<>""" '">0"
End If
If Range("b2").Value <> "" Then
d2 = Range("b2").Value
Else
d2 = "<>""" '">0"
End If
If Range("c2").Value <> "" Then
d3 = Range("c2").Value
Else
d3 = "<>""" '">0"
End If
If Range("d2").Value <> "" Then
d4 = Format(Range("D2"), "m/dd/yyyy")
d41 = Range("D3")
Else
d4 = "<>""" '">0"
End If
With Sheets("A2002").Range("A1:" & lastColum) 'UsedRange
.AutoFilter Field:=1, Criteria1:=d1 'Range("a2")
.AutoFilter Field:=3, Criteria1:=d2 'Range("b2")
.AutoFilter Field:=11, Criteria1:=d3 'Range("c2")
.AutoFilter Field:=24, Criteria1:=d41 & d4 'Range("c2")
.Copy Range("a6")
.AutoFilter
End With
End Sub
Obrigado!