Autofilter Resolvido

cloudrickk

18-09-2015 16:41:52

Boa tarde pessoal,
estou com um problema com um código que eu fiz para filtrar, ele não está filtrando do jeito que eu coloquei ele filtra deixando as linhas em branco e os produtos que ele devia puxar fica tudo oculto... segue abaixo o código que criei.

Private Sub CommandButton1_Click()
On Error GoTo TRATA_ERRO
Dim DTINICIAL As Date
Dim DTFINAL As Date
DTINICIAL = TextBox1
DTFINAL = TextBox2
INCIAL = CLng(DTINICIAL)
Final = CLng(DTFINAL)
If OptionButton1.Value = True Then
Plan3.Cells.AutoFilter FIELD:=2, Criteria1:=">=" & INICIAL, Operator:=xlAnd, Criteria2:="<=" & Final
Plan3.Cells.AutoFilter FIELD:=4, Criteria1:=ComboBox1
A = Application.WorksheetFunction.CountA(Plan3.Columns(1))
Plan3.Range("A1:F" & A).Copy (Plan7.Cells(1, 1))
UserForm4.Label1 = "RELATORIO DE MOVIMENTAÇÃO - ENTRADAS"
UserForm4.Label2 = "PRODUTO:" & ComboBox1
UserForm4.Show

Else
If OptionButton2.Value = True Then
Plan4.Cells.AutoFilter FIELD:=2, Criteria1:=">=" & INICIAL, Operator:=xlAnd, Criteria2:="<=" & Final
Plan4.Cells.AutoFilter FIELD:=4, Criteria1:=ComboBox1
A = Application.WorksheetFunction.CountA(Plan4.Columns(1))
Plan4.Range("A1:F" & A).Copy (Plan7.Cells(1, 1))
UserForm4.Show
UserForm4.Label1 = "RELATORIO DE MOVIMENTAÇÃO - CONSUMO"
UserForm4.Label2 = "PRODUTO:" & ComboBox1


End If
End If
Exit Sub
TRATA_ERRO:
MsgBox "O VALOR DIGITADO NAS CAIXAS DE TEXTO NÃO SÃO VALIDOS", vbInformation, "ATENÇÃO"


End Sub

Private Sub CommandButton2_Click()
End
End Sub

Private Sub UserForm_Click()

End Sub

Private Sub UserForm_Initialize()
A = Application.WorksheetFunction.CountA(Plan5.Columns(1)) + 1
B = 2
While A > B
ComboBox1.AddItem Plan2.Cells(B, 2)
B = B + 1
Wend
End Sub

Em anexo como fica na aba do excel.
Quem conseguir arrumar poderia me explicar onde eu errei?

cloudrickk

20-09-2015 13:51:26

Pessoal se vocês não estiverem entendendo me avisem que vou tentar fazer em uma planilha.

cloudrickk

22-09-2015 10:16:06

Bom dia Pessoal,
Segue a planilha para ter como exemplo, a parte de relatório por produtos que está puxando o relatório em branco na hora de filtrar.
Vai pedir login e senha, é só apertar entra e abrir a planilha novamente.

cloudrickk

04-10-2015 15:15:27

Alguem poderia ajudar?

Reinaldo

04-10-2015 18:35:04

Suas datas nas planilhas de entrada e saída (coluna B), estão como texto. Converta para data
Seu código utilize assim

Código: Selecionar todos

Private Sub CommandButton1_Click()
On Error GoTo TRATA_ERRO
    If OptionButton1.Value = True Then
        Plan3.Cells.AutoFilter FIELD:=2, Criteria1:=">=" & Format(TextBox1, "yyyy/mm/dd"), _
                            Operator:=xlAnd, Criteria2:="<=" & Format(TextBox2, "yyyy/mm/dd")
        Plan3.Cells.AutoFilter FIELD:=4, Criteria1:=ComboBox1
        A = Application.WorksheetFunction.CountA(Plan3.Columns(1))
        Plan3.Range("A1:F" & A).Copy (Plan7.Cells(1, 1))
        UserForm4.Label1 = "RELATORIO DE MOVIMENTAÇÃO - ENTRADAS"
        UserForm4.Label2 = "PRODUTO:" & ComboBox1
        UserForm4.Show
    ElseIf OptionButton2.Value = True Then
        Plan4.Cells.AutoFilter FIELD:=2, Criteria1:=">=" & Format(TextBox1, "yyyy/mm/dd"), _
                                Operator:=xlAnd, Criteria2:="<=" & Format(TextBox2, "yyyy/mm/dd")
        Plan4.Cells.AutoFilter FIELD:=4, Criteria1:=ComboBox1
        A = Application.WorksheetFunction.CountA(Plan4.Columns(1))
        Plan4.Range("A1:F" & A).Copy (Plan7.Cells(1, 1))
        UserForm4.Show
        UserForm4.Label1 = "RELATORIO DE MOVIMENTAÇÃO - CONSUMO"
        UserForm4.Label2 = "PRODUTO:" & ComboBox1
    End If
Exit Sub
TRATA_ERRO:
MsgBox "O VALOR DIGITADO NAS CAIXAS DE TEXTO NÃO SÃO VALIDOS", vbInformation, "ATENÇÃO"
End Sub

cloudrickk

07-10-2015 13:21:53

Bom dia Reinaldo,
Continuou do mesmo jeito.

Reinaldo

07-10-2015 14:23:38

Utilizando seu modelo, fiz o que relatei e funcionou.

Voce atualizou as datas na planilha, estavam como texto.
Disponha seu modelo com as modificações