Ir para conteúdo
Fórum Script Brasil
  • 0

Exibir na ListBox apenas os dados visíveis (filtrados) na tabela


MColucci

Pergunta

Boa noite, quero listar os dados de uma tabela em uma ListBox, mas quando eu filtro a tabela ele continua mostrando tudo, mesmo os dados filtrados, como eu posso resolver isso?

Private Sub CommandButton1_Click()

Dim Sh As Worksheet
Dim i As Long

If txtQtd = "" Then
 txtQtd.SetFocus
Else

Set Sh = Worksheets("Teste")

'Primeira linha com valores (sem filtro na tabela)
i = 4 

Qtd = txtQtd
listTempo.Clear

 With Me.listTempo
  Do Until Sh.Cells(i, 4).Value = ""
   .AddItem Sh.Cells(i, 3).Value
   .List(.ListCount - 1, 1) = Sh.Cells(i, 4).Value
   .List(.ListCount - 1, 2) = Sh.Cells(i, 5).Value
   .List(.ListCount - 1, 3) = Sh.Cells(i, 6).Value
   .List(.ListCount - 1, 4) = Sh.Cells(i, 7).Value
   .List(.ListCount - 1, 5) = Qtd
   i = i + 1
  Loop
 End With

End If

End Sub

 

Editado por MColucci
Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

  • 0

Achei a solução! Bastava uma função "If" a mais, obrigado

Private Sub CommandButton1_Click()

Dim Sh As Worksheet
Dim i As Long

If txtQtd = "" Then
 txtQtd.SetFocus
Else
 Set Sh = Worksheets("Teste")
 i = 4 
 Qtd = txtQtd
 listTempo.Clear

 With Me.listTempo
  Do Until Sh.Cells(i, 4).Value = ""
   If Not Sh.Cells(i, 4).EntireRow.Hidden Then
    .AddItem Sh.Cells(i, 3).Value
    .List(.ListCount - 1, 1) = Sh.Cells(i, 4).Value
    .List(.ListCount - 1, 2) = Sh.Cells(i, 5).Value
    .List(.ListCount - 1, 3) = Sh.Cells(i, 6).Value
    .List(.ListCount - 1, 4) = Sh.Cells(i, 7).Value
    .List(.ListCount - 1, 5) = Qtd
   End If
    i = i + 1
  Loop
 End With

End If

End Sub

 

Editado por MColucci
Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...