Inquiridor
Como corrigir Erro 13, incompatibilidade em ListBox

Pergunta
-
Boa noite.
Sou iniciante em VBA. Estou tentando remover um item da ListBox1, automaticamente, se a coluna 1 da ListBox1 for igual a 0.
Ocorre que dá erro 13, informando que o tipo é incompatível.
Estou executando o código abaixo:
Sub Filtro() Dim linhalistbox As Integer Dim valor_entrada As Integer linhalistbox = 1 With Me.ListBox1 While Me.ListBox1.List(linhalistbox, 1) <> "" valor_entrada = Me.ListBox1.List(linhalistbox, 1) If valor_entrada = 0 Then ListBox1.ListIndex(linhalistbox).RemoveItem End If linhalistbox = linhalistbox + 1 Wend End With End Sub
O erro ocorre na linha :
ListBox1.ListIndex(linhalistbox).RemoveItem
Como converter um tipo de item da ListBox1?
E como aplicar, nesse caso?
Todas as Respostas
-
Option Explicit Sub Filtro() Dim linhalistbox As Integer Dim valor_entrada As Integer linhalistbox = 0 With Me.ListBox1 While .List(.ListCount - 1) <> "" And linhalistbox < .ListCount valor_entrada = .List(linhalistbox) If valor_entrada = 0 Then ListBox1.RemoveItem (linhalistbox) End If linhalistbox = linhalistbox + 1 Wend End With End Sub
Anderson Diniz
- Sugerido como Resposta AndersonFDiniz2 domingo, 10 de setembro de 2017 21:51
-
Sub Filtro2() Dim i As Integer Dim itens As Integer itens = ListBox1.ListCount - 1 For i = 0 To itens If ListBox1.List(i) = 0 Then ListBox1.RemoveItem (i) End If If i > ListBox1.ListCount - 1 Then Exit For End If Next i End Sub
Anderson Diniz
- Sugerido como Resposta AndersonFDiniz2 domingo, 10 de setembro de 2017 22:01
-
Olá, Anderson.
Bom dia.
Agradeço a ajuda.
Tentei as duas formas, mas continua apresentando incompatibilidade no tipo. Erro 13. Tentei usar o CInt, CDbl e nada. o erro persiste.
Vou tentar criar um array para receber o listindex. Será? Tem lógica?
-
-