Eu estava tentando fazer esse código de pequisa inspirado num vídeo que eu achei na internet. A ídeia é fazer uma ListView delimitada pelas datas de incio e fim.
A parte que ta dando erro é esse if:
For W = 4 To Plan2.Range("b1000000").End(xlUp).Row
If TBInicio.Text <= CDate(Plan2.Range("d" & W)) And _
TBFim.Text >= CDate(Plan2.Range("d" & W)) Then
Set item = ListView1.ListItems.Add(Text:=Plan1.Range("b" & W))
item.SubItems(1) = Plan2.Range("c" & W)
item.SubItems(2) = Plan2.Range("d" & W)
item.SubItems(3) = Plan2.Range("e" & W)
item.SubItems(4) = Plan2.Range("f" & W)
item.SubItems(5) = Plan2.Range("g" & W)
item.SubItems(6) = Plan2.Range("h" & W)
End If
Next
esse é o código todo
Private Sub CBRelatorio_Click()
GERAR_RELATORIO
End Sub
Private Sub UserForm_Initialize()
GERAR_RELATORIO
End Sub
Private Sub TBInicio_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii < Asc(0) Or KeyAscii > Asc(9) Then
KeyAscii = 0
End If
End Sub
Private Sub TBFim_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii < Asc(0) Or KeyAscii > Asc(9) Then
KeyAscii = 0
End If
End Sub
Private Sub TBInicio_Change()
TBInicio.MaxLength = 10
If Len(TBInicio) = 2 Or Len(TBInicio) = 5 Then
TBInicio.Text = TBInicio.Text & "/"
End If
End Sub
Private Sub TBFim_Change()
TBFim.MaxLength = 10
If Len(TBFim) = 2 Or Len(TBFim) = 5 Then
TBFim.Text = TBFim.Text & "/"
End If
End Sub
Sub GERAR_RELATORIO()
Dim item As ListItem
Dim W As Integer
ListView1.ColumnHeaders.Clear
ListView1.ListItems.Clear
ListView1.Gridlines = True
ListView1.View = lvwReport
ListView1.FullRowSelect = True
ListView1.ColumnHeaders.Add Text:="Nome do Funcionário", Width:=90, Alignment:=0
ListView1.ColumnHeaders.Add Text:="Departamento", Width:=90, Alignment:=0
ListView1.ColumnHeaders.Add Text:="Data da Movimentação", Width:=65, Alignment:=0
ListView1.ColumnHeaders.Add Text:="Descrição do Produto", Width:=280, Alignment:=0
ListView1.ColumnHeaders.Add Text:="Unidade de Medida", Width:=65, Alignment:=0
ListView1.ColumnHeaders.Add Text:="Entradas", Width:=55, Alignment:=0
ListView1.ColumnHeaders.Add Text:="Retiradas", Width:=55, Alignment:=0
For W = 4 To Plan2.Range("b1000000").End(xlUp).Row
If TBInicio.Text <= CDate(Plan2.Range("d" & W)) And _
TBFim.Text >= CDate(Plan2.Range("d" & W)) Then
Set item = ListView1.ListItems.Add(Text:=Plan1.Range("b" & W))
item.SubItems(1) = Plan2.Range("c" & W)
item.SubItems(2) = Plan2.Range("d" & W)
item.SubItems(3) = Plan2.Range("e" & W)
item.SubItems(4) = Plan2.Range("f" & W)
item.SubItems(5) = Plan2.Range("g" & W)
item.SubItems(6) = Plan2.Range("h" & W)
End If
Next
End Sub
Eu segui as intruções desse blog:
https://www.solucoesemexcel.com.br/single-post/2017/08/16/Criando-UserForm-no-VBA---Excel-Parte-Final