Filtro entre Datas
Enviado: 06 Ago 2022 às 19:50
Boa noite, estou com esse código, porem não esta filtrando, quando clico no botão para filtrar a listbox fica vazio,
meu listbox já abre com os dados carregados!
segue o código, desde já agradeço a todos.
Private Sub BtnPesquisarEntrada_Click()
'condição se nao for selecionado as datas para pesquisa não vai executar o codigo
If Me.TxtDataIncio = "" Or Me.TxtDataFinal = "" Then
MsgBox ("Favor preencher a data incial e final para a pesquisa")
Exit Sub
End If
Dim Linha, LinhaListbox As Long
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Entrada")
Linha = 2
LinhaListbox = 0
ListBoxEntrada.Clear
With ws
While ws.Cells(Linha, 1).Value <> Empty
If ws.Cells(Linha, 2) >= CDate(TxtDataIncio.Value) And Cells(Linha, 2) <= CDate(TxtDataFinal.Value) Then
With FormEntrada.ListBoxEntrada
.AddItem
.List(LinhaListbox, 0) = ws.Cells(Linha, 1) 'Equipamento A
.List(LinhaListbox, 1) = ws.Cells(Linha, 2) 'Quantidade' B
.List(LinhaListbox, 2) = ws.Cells(Linha, 3) 'NF C
.List(LinhaListbox, 3) = ws.Cells(Linha, 4) 'Data D
.List(LinhaListbox, 4) = ws.Cells(Linha, 5) 'Obs E
LinhaListbox = LinhaListbox + 1
End With
End If
Linha = Linha + 1
Wend
End With
LblRegistros.Caption = LinhaListbox & " Registro(s) Encontrado(s)."
'End With
End Sub
meu listbox já abre com os dados carregados!
segue o código, desde já agradeço a todos.
Private Sub BtnPesquisarEntrada_Click()
'condição se nao for selecionado as datas para pesquisa não vai executar o codigo
If Me.TxtDataIncio = "" Or Me.TxtDataFinal = "" Then
MsgBox ("Favor preencher a data incial e final para a pesquisa")
Exit Sub
End If
Dim Linha, LinhaListbox As Long
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Entrada")
Linha = 2
LinhaListbox = 0
ListBoxEntrada.Clear
With ws
While ws.Cells(Linha, 1).Value <> Empty
If ws.Cells(Linha, 2) >= CDate(TxtDataIncio.Value) And Cells(Linha, 2) <= CDate(TxtDataFinal.Value) Then
With FormEntrada.ListBoxEntrada
.AddItem
.List(LinhaListbox, 0) = ws.Cells(Linha, 1) 'Equipamento A
.List(LinhaListbox, 1) = ws.Cells(Linha, 2) 'Quantidade' B
.List(LinhaListbox, 2) = ws.Cells(Linha, 3) 'NF C
.List(LinhaListbox, 3) = ws.Cells(Linha, 4) 'Data D
.List(LinhaListbox, 4) = ws.Cells(Linha, 5) 'Obs E
LinhaListbox = LinhaListbox + 1
End With
End If
Linha = Linha + 1
Wend
End With
LblRegistros.Caption = LinhaListbox & " Registro(s) Encontrado(s)."
'End With
End Sub