LISTBOX COM MAIS DE 10 COLUNAS

giba

06-04-2014 18:39:40

Olá a todos,

Tenho o seguinte código para polular a listbox, mas não consigo aumentar a quantidade de colunas, o código aceita apenas 10 colunas e eu preciso de 12. Será que alguém poderia me ajudar. Desde já Agradeco.

'-----------------------------------------
If mandado.Value = "" Then
ListBox3.Clear
Else
ListBox3.ColumnWidths = "140 pt; 60 pt; 80 pt ;90 pt; 100 pt; 80 pt;80 pt;80 pt;80 pt;80 pt;80 pt;80 pt"
ListBox3.ColumnCount = 12 'Define a qde de Colunas no Listbox
ListBox3.Clear
With Plan2
strObjetoBuscar = mandado.Value
strObjetoBuscar = LCase(strObjetoBuscar)

For E = 2 To 10000
lngResultado = InStr(1, .Cells(E, 5), strObjetoBuscar, vbTextCompare)
If lngResultado > 0 Then

ListBox3.AddItem .Range("a" & E).Value
ListBox3.List(ListBox3.ListCount - 1, 1) = .Range("b" & E).Value
ListBox3.List(ListBox3.ListCount - 1, 2) = .Range("c" & E).Value
ListBox3.List(ListBox3.ListCount - 1, 3) = .Range("d" & E).Value
ListBox3.List(ListBox3.ListCount - 1, 4) = .Range("e" & E).Value
ListBox3.List(ListBox3.ListCount - 1, 5) = .Range("f" & E).Value
ListBox3.List(ListBox3.ListCount - 1, 6) = .Range("G" & E).Value
ListBox3.List(ListBox3.ListCount - 1, 7) = .Range("H" & E).Value
ListBox3.List(ListBox3.ListCount - 1, 8) = .Range("I" & E).Value
ListBox3.List(ListBox3.ListCount - 1, 9) = .Range("J" & E).Value
'DÁ ERRO A PARTIR DESSA LINHA
ListBox3.List(ListBox3.ListCount - 1, 10) = .Range("K" & E).Value
ListBox3.List(ListBox3.ListCount - 1, 11) = .Range("L" & E).Value

End If
Next E
End With
End If
'-----------------------------------------

nerybahia

09-04-2014 12:57:31

Olá, giba, veja bem, quando utilizamos listbox ele tem limitações na questão das colunas é permitido apenas inclusão de 10 colunas, para inclusão de mais colunas utilize o listview.

giba

10-04-2014 21:27:16

Obrigado pela dica, porém trabalho no Fórum e os computadores não têm o listview instalados em seus sistema windows e não é permitida qualquer alteração. Por este motivo estou tentando fazer com a listbox. Obrigado. :mrgreen:

Mauro Coutinho

10-04-2014 22:48:35

giba escreveu:Obrigado pela dica, porém trabalho no Fórum e os computadores não têm o listview instalados em seus sistema windows e não é permitida qualquer alteração. Por este motivo estou tentando fazer com a listbox. Obrigado. :mrgreen:
Giba, não precisa instalar nenhum programa o controle (Biblioteca) é instalada automaticamente quando se instala o pacote office, só é preciso Habilita-lo, veja como fazer no link abaixo:
Habilitar o Controle ListView
viewtopic.php?f=16&t=1723#.U0cdGVVdXQQ

Quanto qde de colunas, em VBA você está limitado a 10 colunas (0-9), utilizando RowSource podemos ter 256 colunas
usando additem o limite são 10 colunas
usando RowSource 256 colunas

Simplificando, podemos utilizar um ARRAY tambem, mas dos exemplos que encontrei o código abaixo irá lhe servir :

Código: Selecionar todos

Private Sub CommandButton2_Click()

Dim c As Range, a() As String, n As Long, i As Long

ListBox1.ColumnCount = 12

    With Plan1
        Set Rng = .Range("A1", .Range("A1").End(xlDown))
        
        Me.ListBox1.Clear
        
        For Each c In Rng
            n = n + 1: ReDim Preserve a(1 To 12, 1 To n)
            For i = 1 To 12
                a(i, n) = c.Offset(, i - 1).Value
            Next
        Next
    End With
    
'Preenche o Listbox
If n > 0 Then Me.ListBox1.Column = a
End Sub
Neste codigo estamos utilizando 12 colunas, é só acertar o nome da planilha e a quantidade de colunas.

Uma outra dica seria fazer a filtragem dos dados que quer para uma outra aba e depois carregar o Listbox.

[]s