1
I’m trying to carry a ListView
with more than thirty columns using the following code:
With ListV_P
Sheets("BANCO").Select
Dim UltimaLinha As Variant
Dim Linha As String
'.GetFirstVisible = True 'Abilita as linhas de Grades
'.View = lvwReport
'.FullRowSelect = True 'Seleciona a linha completa
.Gridlines = True
.View = lvwReport
.FullRowSelect = True
'Criar Cabeçalho
.ColumnHeaders.Add Text:="ID", Width:=40
.ColumnHeaders.Add Text:="NOME", Width:=100
.ColumnHeaders.Add Text:="ENDEREÇO", Width:=120
.ColumnHeaders.Add Text:="BAIRRO", Width:=60
.ColumnHeaders.Add Text:="CIDADE", Width:=70
.ColumnHeaders.Add Text:="SEXO", Width:=40
.ColumnHeaders.Add Text:="IDADE", Width:=40
.ColumnHeaders.Add Text:="CELULAR 1", Width:=70
.ColumnHeaders.Add Text:="CELULAR 2", Width:=70
.ColumnHeaders.Add Text:="E-MAIL", Width:=85
.ColumnHeaders.Add Text:="ESTADO CIVIL", Width:=40
.ColumnHeaders.Add Text:="FORMAÇÃO ACADÊMICA", Width:=90
.ColumnHeaders.Add Text:="CURSO 1", Width:=90
.ColumnHeaders.Add Text:="CURSO 2", Width:=90
.ColumnHeaders.Add Text:="CURSO 3", Width:=90
.ColumnHeaders.Add Text:="DEFICIÊNCIA", Width:=60
.ColumnHeaders.Add Text:="ÁREA DE INTERESSE 1", Width:=70
.ColumnHeaders.Add Text:="ÁREA DE INTERESSE 2", Width:=70
.ColumnHeaders.Add Text:="ÁREA DE INTERESSE 3", Width:=70
.ColumnHeaders.Add Text:="EXP. PROFISSIONAL 1", Width:=70
.ColumnHeaders.Add Text:="CARGO 1", Width:=60
.ColumnHeaders.Add Text:="TEMPO", Width:=60
.ColumnHeaders.Add Text:="EXP. PROFISSIONAL 2", Width:=70
.ColumnHeaders.Add Text:="CARGO 2", Width:=60
.ColumnHeaders.Add Text:="TEMPO 2", Width:=60
.ColumnHeaders.Add Text:="EXP. PROFISSIONAL 3", Width:=70
.ColumnHeaders.Add Text:="CARGO 3", Width:=60
.ColumnHeaders.Add Text:="TEMPO 3", Width:=60
.ColumnHeaders.Add Text:="PROGRAMA SOCIAL", Width:=70
.ColumnHeaders.Add Text:="INDICAÇÃO", Width:=40
.ColumnHeaders.Add Text:="N° DO ENCAMINHAMENTO", Width:=40, Alignment:=2 'Alinhamento Centralizado
End With
ListV_P.ListItems.Clear 'Limpa os dados
UltimaLinha = Cells(Rows.Count, "1").End(xlUp).Row
'Lin = 7 'Comerça a exibir os dados apartir da linha 4 da tabela selecionada
For x = 7 To UltimaLinha
Set Lista = ListV_P.ListItems.Add(Text:=Cells(x, "A").Value)
Lista.ListSubItems.Add Text:=Cells(x, "B").Value
Lista.ListSubItems.Add Text:=Cells(x, "C").Value
Lista.ListSubItems.Add Text:=Cells(x, "E").Value
Lista.ListSubItems.Add Text:=Cells(x, "F").Value
Lista.ListSubItems.Add Text:=Cells(x, "F").Value
Lista.ListSubItems.Add Text:=Cells(x, "I").Value
Lista.ListSubItems.Add Text:=Cells(x, "N").Value
Lista.ListSubItems.Add Text:=Cells(x, "P").Value
Lista.ListSubItems.Add Text:=Cells(x, "Q").Value
Lista.ListSubItems.Add Text:=Cells(x, "R").Value
Lista.ListSubItems.Add Text:=Cells(x, "S").Value
Lista.ListSubItems.Add Text:=Cells(x, "T").Value
Lista.ListSubItems.Add Text:=Cells(x, "U").Value
Lista.ListSubItems.Add Text:=Cells(x, "V").Value
Lista.ListSubItems.Add Text:=Cells(x, "W").Value
Lista.ListSubItems.Add Text:=Cells(x, "Y").Value
Lista.ListSubItems.Add Text:=Cells(x, "Z").Value
Lista.ListSubItems.Add Text:=Cells(x, "AA").Value
Lista.ListSubItems.Add Text:=Cells(x, "AB").Value
Lista.ListSubItems.Add Text:=Cells(x, "AC").Value
Lista.ListSubItems.Add Text:=Cells(x, "AD").Value
Lista.ListSubItems.Add Text:=Cells(x, "AE").Value
Lista.ListSubItems.Add Text:=Cells(x, "AF").Value
Lista.ListSubItems.Add Text:=Cells(x, "AG").Value
Lista.ListSubItems.Add Text:=Cells(x, "AH").Value
Lista.ListSubItems.Add Text:=Cells(x, "AI").Value
Lista.ListSubItems.Add Text:=Cells(x, "AJ").Value
Lista.ListSubItems.Add Text:=Cells(x, "AK").Value
Lista.ListSubItems.Add Text:=Cells(x, "AL").Value
Lista.ListSubItems.Add Text:=Cells(x, "AM").Value
Lista.ListSubItems.Add Text:=Cells(x, "AN").Value
Next
But when I give the command to execute the code VBA presents me an error message:
Runtime error '1004': Application definition error or object-defining.
Please someone help me there. I am Beginner in VBA
Behold this tutorial or if using Listbox, use
.RowSource
and see this tutorial– danieltakeshi