VBA Listbox Automatic Filter

Asked

Viewed 204 times

-1

You can help me, I’m trying to make mine listbox load the spreadsheet 3, but he carries only the first line

Sub Filtro()

Dim linha, linhalistbox As Integer
Dim valor_celula As String

linhalistbox = 0
linha = 1

Planilha3.Select

With Planilha3

    While .Cells(linha, 9).Value <> ""
    
    valor_celula = .Cells(linha, 5).Value
    If UCase(Left(valor_celula, Len(txt_referencia.Text))) = UCase(txt_referencia.Text) Then
    valor_celula = .Cells(linha, 6).Value
    If UCase(Left(valor_celula, Len(txt_tamanho.Text))) = UCase(txt_tamanho.Text) Then
    
    
Me.ListBox1.ColumnWidths = "60;100;40;50;50;40;40;60;60"

    With ListBox1
    .AddItem
    .List(linhalistbox, 0) = Planilha3.Cells(linha, 1)
    .List(linhalistbox, 1) = Planilha3.Cells(linha, 2)
    .List(linhalistbox, 2) = Planilha3.Cells(linha, 3)
    .List(linhalistbox, 3) = Planilha3.Cells(linha, 4)
    .List(linhalistbox, 4) = Planilha3.Cells(linha, 5)
    .List(linhalistbox, 5) = Planilha3.Cells(linha, 6)
    .List(linhalistbox, 6) = Planilha3.Cells(linha, 7)
    .List(linhalistbox, 7) = Planilha3.Cells(linha, 8)
    .List(linhalistbox, 8) = Planilha3.Cells(linha, 9)


End With

linhalistbox = linhalistbox + 1

End If
End If

linha = linha + 1

Wend

End With

End Sub

Private Sub txt_referencia_Change()
Call Filtro

End Sub

Private Sub UserForm_Click()
Call Filtro
End Sub

Private Sub UserForm_Initialize()
Call Filtro

End Sub

  • What I saw was missing a loop that makes that after loading the first line it remakes the operation you can use for next or until

1 answer

0

Issac changed from that;

.List(linhalistbox, 0) = Planilha3.Cells(linha, 1)
.List(linhalistbox, 1) = Planilha3.Cells(linha, 2)
.List(linhalistbox, 2) = Planilha3.Cells(linha, 3)
.List(linhalistbox, 3) = Planilha3.Cells(linha, 4)
.List(linhalistbox, 4) = Planilha3.Cells(linha, 5)
.List(linhalistbox, 5) = Planilha3.Cells(linha, 6)
.List(linhalistbox, 6) = Planilha3.Cells(linha, 7)
.List(linhalistbox, 7) = Planilha3.Cells(linha, 8)
.List(linhalistbox, 8) = Planilha3.Cells(linha, 9)

For that, see if it works.

.RowSource = "Planilha3!A1:H1"
  • Paulo, good evening. Thank you. but it didn’t work. Error 380. It wasn’t possible to define Rowsource property. Invalid property value. Honestly, I’m giving up already, something so simple and I’m not able to conclude.

  • No, don’t give up. We can talk i if it’s possible you send me, [email protected]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.