Listview filtrar po...
 
Notifications
Clear all

Listview filtrar por data

3 Posts
2 Usuários
1 Likes
819 Visualizações
(@dunguinha)
Posts: 61
Trusted Member
Topic starter
 

Olá pessoal.

Peço o favor para um abençoado me ajudar a desenvolver um código para busca por data no listview.

Vi muitos códigos na net mas nenhum atende minha necessidade.

Preciso que carregue o listview de acordo com data inicial e data final, somente isso.

Só um detalhe, quando a caixa data final não for preenchida a busca se dá até última data da planilha.

 
Postado : 31/08/2020 10:31 pm
(@anderson)
Posts: 203
Reputable Member
 


Private Sub btnFiltrar_Click()

Dim linha As Long
Dim liSTA As ListItem




If Me.txtDataFinal.Text <> "" And IsDate(Me.txtDataFinal.Text) Then
If Me.txtDataInicial.Text <> "" And IsDate(Me.txtDataInicial.Text) Then
linha = 4
While Plan1.Range("B" & linha).Value <> ""




If CDate(Plan1.Range("B" & linha).Value) >= CDate(Me.txtDataInicial.Text) Then
If CDate(Plan1.Range("B" & linha).Value) <= CDate(Me.txtDataFinal.Text) Then

Set liSTA = ListView1.ListItems.Add(, , Plan1.Range("B" & linha).Value)

liSTA.SubItems(1) = Plan1.Range("C" & linha).Value
liSTA.SubItems(2) = Plan1.Range("D" & linha).Value
End If

End If
linha = linha + 1




Wend

End If
End If




If Me.txtDataFinal.Text = "" Then
If Me.txtDataInicial.Text <> "" And IsDate(Me.txtDataInicial.Text) Then
linha = 4
While Plan1.Range("B" & linha).Value <> ""




If CDate(Plan1.Range("B" & linha).Value) >= CDate(Me.txtDataInicial.Text) Then
'If CDate(Plan1.Range("B" & linha).Value) <= CDate(Me.txtDataFinal.Text) Then

Set liSTA = ListView1.ListItems.Add(, , Plan1.Range("B" & linha).Value)

liSTA.SubItems(1) = Plan1.Range("C" & linha).Value
liSTA.SubItems(2) = Plan1.Range("D" & linha).Value
'End If

End If
linha = linha + 1




Wend

End If
End If







End Sub




Private Sub txtDataFinal_Change()
If Len(Me.txtDataFinal) = 2 Then
Me.txtDataFinal.Value = Me.txtDataFinal.Value & "/"
ElseIf Len(Me.txtDataFinal) = 5 Then
Me.txtDataFinal.Value = Me.txtDataFinal.Value & "/"
End If
End Sub

Private Sub txtDataInicial_Change()

If Len(Me.txtDataInicial) = 2 Then
Me.txtDataInicial.Value = Me.txtDataInicial.Value & "/"
ElseIf Len(Me.txtDataInicial) = 5 Then
Me.txtDataInicial.Value = Me.txtDataInicial.Value & "/"
End If

End Sub

Private Sub UserForm_Initialize()

With ListView1
.View = lvwReport
.FullRowSelect = True
.Gridlines = True
.ColumnHeaders.Add Text:="Data", Width:=70
.ColumnHeaders.Add Text:="Nome", Width:=250
.ColumnHeaders.Add Text:="Valor", Width:=70
.Font.Size = 9
End With

End Sub

Editado pela Moderação. Motivo:

Membro @anderson:  Novamente pedimos utilizar o botão Código (< >) sempre que for inserir código VBA ou Fórmulas.

Este post foi modificado 4 anos atrás 2 vezes por Anderson

Em 90% dos casos em que não se anexa o arquivo, ocorrem mal-entendidos, gerando perda de tempo de ambos os lados.

 
Postado : 01/09/2020 10:55 am
Dunguinha reacted
(@dunguinha)
Posts: 61
Trusted Member
Topic starter
 

Show de bola. 

Muito obrigado pela força Anderson.

 
Postado : 01/09/2020 12:57 pm