How to Load a listview with more than 30 columns?

Asked

Viewed 1,025 times

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

1 answer

0

Sample data

With the program of Excelmaniacos, a test was performed with data from column A to AN, from row 7 to 80. As in the table below:

+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+------+------+------+------+------+------+------+------+------+------+------+------+------+
| A7  | B7  | C7  | D7  | E7  | F7  | G7  | H7  | I7  | J7  | K7  | L7  | M7  | N7  | O7  | P7  | Q7  | R7  | S7  | T7  | U7  | V7  | W7  | X7  | Y7  | Z7  | AA7  | AB7  | AC7  | AD7  | AE7  | AF7  | AG7  | AH7  | AI7  | AJ7  | AK7  | AL7  | AM7  | AN7  |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+------+------+------+------+------+------+------+------+------+------+------+------+------+
| A8  | B8  | C8  | D8  | E8  | F8  | G8  | H8  | I8  | J8  | K8  | L8  | M8  | N8  | O8  | P8  | Q8  | R8  | S8  | T8  | U8  | V8  | W8  | X8  | Y8  | Z8  | AA8  | AB8  | AC8  | AD8  | AE8  | AF8  | AG8  | AH8  | AI8  | AJ8  | AK8  | AL8  | AM8  | AN8  |
| A9  | B9  | C9  | D9  | E9  | F9  | G9  | H9  | I9  | J9  | K9  | L9  | M9  | N9  | O9  | P9  | Q9  | R9  | S9  | T9  | U9  | V9  | W9  | X9  | Y9  | Z9  | AA9  | AB9  | AC9  | AD9  | AE9  | AF9  | AG9  | AH9  | AI9  | AJ9  | AK9  | AL9  | AM9  | AN9  |
| A10 | B10 | C10 | D10 | E10 | F10 | G10 | H10 | I10 | J10 | K10 | L10 | M10 | N10 | O10 | P10 | Q10 | R10 | S10 | T10 | U10 | V10 | W10 | X10 | Y10 | Z10 | AA10 | AB10 | AC10 | AD10 | AE10 | AF10 | AG10 | AH10 | AI10 | AJ10 | AK10 | AL10 | AM10 | AN10 |
| A11 | B11 | C11 | D11 | E11 | F11 | G11 | H11 | I11 | J11 | K11 | L11 | M11 | N11 | O11 | P11 | Q11 | R11 | S11 | T11 | U11 | V11 | W11 | X11 | Y11 | Z11 | AA11 | AB11 | AC11 | AD11 | AE11 | AF11 | AG11 | AH11 | AI11 | AJ11 | AK11 | AL11 | AM11 | AN11 |
| A12 | B12 | C12 | D12 | E12 | F12 | G12 | H12 | I12 | J12 | K12 | L12 | M12 | N12 | O12 | P12 | Q12 | R12 | S12 | T12 | U12 | V12 | W12 | X12 | Y12 | Z12 | AA12 | AB12 | AC12 | AD12 | AE12 | AF12 | AG12 | AH12 | AI12 | AJ12 | AK12 | AL12 | AM12 | AN12 |
| A13 | B13 | C13 | D13 | E13 | F13 | G13 | H13 | I13 | J13 | K13 | L13 | M13 | N13 | O13 | P13 | Q13 | R13 | S13 | T13 | U13 | V13 | W13 | X13 | Y13 | Z13 | AA13 | AB13 | AC13 | AD13 | AE13 | AF13 | AG13 | AH13 | AI13 | AJ13 | AK13 | AL13 | AM13 | AN13 |
| A14 | B14 | C14 | D14 | E14 | F14 | G14 | H14 | I14 | J14 | K14 | L14 | M14 | N14 | O14 | P14 | Q14 | R14 | S14 | T14 | U14 | V14 | W14 | X14 | Y14 | Z14 | AA14 | AB14 | AC14 | AD14 | AE14 | AF14 | AG14 | AH14 | AI14 | AJ14 | AK14 | AL14 | AM14 | AN14 |
| A15 | B15 | C15 | D15 | E15 | F15 | G15 | H15 | I15 | J15 | K15 | L15 | M15 | N15 | O15 | P15 | Q15 | R15 | S15 | T15 | U15 | V15 | W15 | X15 | Y15 | Z15 | AA15 | AB15 | AC15 | AD15 | AE15 | AF15 | AG15 | AH15 | AI15 | AJ15 | AK15 | AL15 | AM15 | AN15 |
| A16 | B16 | C16 | D16 | E16 | F16 | G16 | H16 | I16 | J16 | K16 | L16 | M16 | N16 | O16 | P16 | Q16 | R16 | S16 | T16 | U16 | V16 | W16 | X16 | Y16 | Z16 | AA16 | AB16 | AC16 | AD16 | AE16 | AF16 | AG16 | AH16 | AI16 | AJ16 | AK16 | AL16 | AM16 | AN16 |
| A17 | B17 | C17 | D17 | E17 | F17 | G17 | H17 | I17 | J17 | K17 | L17 | M17 | N17 | O17 | P17 | Q17 | R17 | S17 | T17 | U17 | V17 | W17 | X17 | Y17 | Z17 | AA17 | AB17 | AC17 | AD17 | AE17 | AF17 | AG17 | AH17 | AI17 | AJ17 | AK17 | AL17 | AM17 | AN17 |
| A18 | B18 | C18 | D18 | E18 | F18 | G18 | H18 | I18 | J18 | K18 | L18 | M18 | N18 | O18 | P18 | Q18 | R18 | S18 | T18 | U18 | V18 | W18 | X18 | Y18 | Z18 | AA18 | AB18 | AC18 | AD18 | AE18 | AF18 | AG18 | AH18 | AI18 | AJ18 | AK18 | AL18 | AM18 | AN18 |
| A19 | B19 | C19 | D19 | E19 | F19 | G19 | H19 | I19 | J19 | K19 | L19 | M19 | N19 | O19 | P19 | Q19 | R19 | S19 | T19 | U19 | V19 | W19 | X19 | Y19 | Z19 | AA19 | AB19 | AC19 | AD19 | AE19 | AF19 | AG19 | AH19 | AI19 | AJ19 | AK19 | AL19 | AM19 | AN19 |
| A20 | B20 | C20 | D20 | E20 | F20 | G20 | H20 | I20 | J20 | K20 | L20 | M20 | N20 | O20 | P20 | Q20 | R20 | S20 | T20 | U20 | V20 | W20 | X20 | Y20 | Z20 | AA20 | AB20 | AC20 | AD20 | AE20 | AF20 | AG20 | AH20 | AI20 | AJ20 | AK20 | AL20 | AM20 | AN20 |
| A21 | B21 | C21 | D21 | E21 | F21 | G21 | H21 | I21 | J21 | K21 | L21 | M21 | N21 | O21 | P21 | Q21 | R21 | S21 | T21 | U21 | V21 | W21 | X21 | Y21 | Z21 | AA21 | AB21 | AC21 | AD21 | AE21 | AF21 | AG21 | AH21 | AI21 | AJ21 | AK21 | AL21 | AM21 | AN21 |
| A22 | B22 | C22 | D22 | E22 | F22 | G22 | H22 | I22 | J22 | K22 | L22 | M22 | N22 | O22 | P22 | Q22 | R22 | S22 | T22 | U22 | V22 | W22 | X22 | Y22 | Z22 | AA22 | AB22 | AC22 | AD22 | AE22 | AF22 | AG22 | AH22 | AI22 | AJ22 | AK22 | AL22 | AM22 | AN22 |
| A23 | B23 | C23 | D23 | E23 | F23 | G23 | H23 | I23 | J23 | K23 | L23 | M23 | N23 | O23 | P23 | Q23 | R23 | S23 | T23 | U23 | V23 | W23 | X23 | Y23 | Z23 | AA23 | AB23 | AC23 | AD23 | AE23 | AF23 | AG23 | AH23 | AI23 | AJ23 | AK23 | AL23 | AM23 | AN23 |
| A24 | B24 | C24 | D24 | E24 | F24 | G24 | H24 | I24 | J24 | K24 | L24 | M24 | N24 | O24 | P24 | Q24 | R24 | S24 | T24 | U24 | V24 | W24 | X24 | Y24 | Z24 | AA24 | AB24 | AC24 | AD24 | AE24 | AF24 | AG24 | AH24 | AI24 | AJ24 | AK24 | AL24 | AM24 | AN24 |
| A25 | B25 | C25 | D25 | E25 | F25 | G25 | H25 | I25 | J25 | K25 | L25 | M25 | N25 | O25 | P25 | Q25 | R25 | S25 | T25 | U25 | V25 | W25 | X25 | Y25 | Z25 | AA25 | AB25 | AC25 | AD25 | AE25 | AF25 | AG25 | AH25 | AI25 | AJ25 | AK25 | AL25 | AM25 | AN25 |
| A26 | B26 | C26 | D26 | E26 | F26 | G26 | H26 | I26 | J26 | K26 | L26 | M26 | N26 | O26 | P26 | Q26 | R26 | S26 | T26 | U26 | V26 | W26 | X26 | Y26 | Z26 | AA26 | AB26 | AC26 | AD26 | AE26 | AF26 | AG26 | AH26 | AI26 | AJ26 | AK26 | AL26 | AM26 | AN26 |
| A27 | B27 | C27 | D27 | E27 | F27 | G27 | H27 | I27 | J27 | K27 | L27 | M27 | N27 | O27 | P27 | Q27 | R27 | S27 | T27 | U27 | V27 | W27 | X27 | Y27 | Z27 | AA27 | AB27 | AC27 | AD27 | AE27 | AF27 | AG27 | AH27 | AI27 | AJ27 | AK27 | AL27 | AM27 | AN27 |
| A28 | B28 | C28 | D28 | E28 | F28 | G28 | H28 | I28 | J28 | K28 | L28 | M28 | N28 | O28 | P28 | Q28 | R28 | S28 | T28 | U28 | V28 | W28 | X28 | Y28 | Z28 | AA28 | AB28 | AC28 | AD28 | AE28 | AF28 | AG28 | AH28 | AI28 | AJ28 | AK28 | AL28 | AM28 | AN28 |
| A29 | B29 | C29 | D29 | E29 | F29 | G29 | H29 | I29 | J29 | K29 | L29 | M29 | N29 | O29 | P29 | Q29 | R29 | S29 | T29 | U29 | V29 | W29 | X29 | Y29 | Z29 | AA29 | AB29 | AC29 | AD29 | AE29 | AF29 | AG29 | AH29 | AI29 | AJ29 | AK29 | AL29 | AM29 | AN29 |
| A30 | B30 | C30 | D30 | E30 | F30 | G30 | H30 | I30 | J30 | K30 | L30 | M30 | N30 | O30 | P30 | Q30 | R30 | S30 | T30 | U30 | V30 | W30 | X30 | Y30 | Z30 | AA30 | AB30 | AC30 | AD30 | AE30 | AF30 | AG30 | AH30 | AI30 | AJ30 | AK30 | AL30 | AM30 | AN30 |
| A31 | B31 | C31 | D31 | E31 | F31 | G31 | H31 | I31 | J31 | K31 | L31 | M31 | N31 | O31 | P31 | Q31 | R31 | S31 | T31 | U31 | V31 | W31 | X31 | Y31 | Z31 | AA31 | AB31 | AC31 | AD31 | AE31 | AF31 | AG31 | AH31 | AI31 | AJ31 | AK31 | AL31 | AM31 | AN31 |
| A32 | B32 | C32 | D32 | E32 | F32 | G32 | H32 | I32 | J32 | K32 | L32 | M32 | N32 | O32 | P32 | Q32 | R32 | S32 | T32 | U32 | V32 | W32 | X32 | Y32 | Z32 | AA32 | AB32 | AC32 | AD32 | AE32 | AF32 | AG32 | AH32 | AI32 | AJ32 | AK32 | AL32 | AM32 | AN32 |
| A33 | B33 | C33 | D33 | E33 | F33 | G33 | H33 | I33 | J33 | K33 | L33 | M33 | N33 | O33 | P33 | Q33 | R33 | S33 | T33 | U33 | V33 | W33 | X33 | Y33 | Z33 | AA33 | AB33 | AC33 | AD33 | AE33 | AF33 | AG33 | AH33 | AI33 | AJ33 | AK33 | AL33 | AM33 | AN33 |
| A34 | B34 | C34 | D34 | E34 | F34 | G34 | H34 | I34 | J34 | K34 | L34 | M34 | N34 | O34 | P34 | Q34 | R34 | S34 | T34 | U34 | V34 | W34 | X34 | Y34 | Z34 | AA34 | AB34 | AC34 | AD34 | AE34 | AF34 | AG34 | AH34 | AI34 | AJ34 | AK34 | AL34 | AM34 | AN34 |
| A35 | B35 | C35 | D35 | E35 | F35 | G35 | H35 | I35 | J35 | K35 | L35 | M35 | N35 | O35 | P35 | Q35 | R35 | S35 | T35 | U35 | V35 | W35 | X35 | Y35 | Z35 | AA35 | AB35 | AC35 | AD35 | AE35 | AF35 | AG35 | AH35 | AI35 | AJ35 | AK35 | AL35 | AM35 | AN35 |
| A36 | B36 | C36 | D36 | E36 | F36 | G36 | H36 | I36 | J36 | K36 | L36 | M36 | N36 | O36 | P36 | Q36 | R36 | S36 | T36 | U36 | V36 | W36 | X36 | Y36 | Z36 | AA36 | AB36 | AC36 | AD36 | AE36 | AF36 | AG36 | AH36 | AI36 | AJ36 | AK36 | AL36 | AM36 | AN36 |
| A37 | B37 | C37 | D37 | E37 | F37 | G37 | H37 | I37 | J37 | K37 | L37 | M37 | N37 | O37 | P37 | Q37 | R37 | S37 | T37 | U37 | V37 | W37 | X37 | Y37 | Z37 | AA37 | AB37 | AC37 | AD37 | AE37 | AF37 | AG37 | AH37 | AI37 | AJ37 | AK37 | AL37 | AM37 | AN37 |
| A38 | B38 | C38 | D38 | E38 | F38 | G38 | H38 | I38 | J38 | K38 | L38 | M38 | N38 | O38 | P38 | Q38 | R38 | S38 | T38 | U38 | V38 | W38 | X38 | Y38 | Z38 | AA38 | AB38 | AC38 | AD38 | AE38 | AF38 | AG38 | AH38 | AI38 | AJ38 | AK38 | AL38 | AM38 | AN38 |
| A39 | B39 | C39 | D39 | E39 | F39 | G39 | H39 | I39 | J39 | K39 | L39 | M39 | N39 | O39 | P39 | Q39 | R39 | S39 | T39 | U39 | V39 | W39 | X39 | Y39 | Z39 | AA39 | AB39 | AC39 | AD39 | AE39 | AF39 | AG39 | AH39 | AI39 | AJ39 | AK39 | AL39 | AM39 | AN39 |
| A40 | B40 | C40 | D40 | E40 | F40 | G40 | H40 | I40 | J40 | K40 | L40 | M40 | N40 | O40 | P40 | Q40 | R40 | S40 | T40 | U40 | V40 | W40 | X40 | Y40 | Z40 | AA40 | AB40 | AC40 | AD40 | AE40 | AF40 | AG40 | AH40 | AI40 | AJ40 | AK40 | AL40 | AM40 | AN40 |
| A41 | B41 | C41 | D41 | E41 | F41 | G41 | H41 | I41 | J41 | K41 | L41 | M41 | N41 | O41 | P41 | Q41 | R41 | S41 | T41 | U41 | V41 | W41 | X41 | Y41 | Z41 | AA41 | AB41 | AC41 | AD41 | AE41 | AF41 | AG41 | AH41 | AI41 | AJ41 | AK41 | AL41 | AM41 | AN41 |
| A42 | B42 | C42 | D42 | E42 | F42 | G42 | H42 | I42 | J42 | K42 | L42 | M42 | N42 | O42 | P42 | Q42 | R42 | S42 | T42 | U42 | V42 | W42 | X42 | Y42 | Z42 | AA42 | AB42 | AC42 | AD42 | AE42 | AF42 | AG42 | AH42 | AI42 | AJ42 | AK42 | AL42 | AM42 | AN42 |
| A43 | B43 | C43 | D43 | E43 | F43 | G43 | H43 | I43 | J43 | K43 | L43 | M43 | N43 | O43 | P43 | Q43 | R43 | S43 | T43 | U43 | V43 | W43 | X43 | Y43 | Z43 | AA43 | AB43 | AC43 | AD43 | AE43 | AF43 | AG43 | AH43 | AI43 | AJ43 | AK43 | AL43 | AM43 | AN43 |
| A44 | B44 | C44 | D44 | E44 | F44 | G44 | H44 | I44 | J44 | K44 | L44 | M44 | N44 | O44 | P44 | Q44 | R44 | S44 | T44 | U44 | V44 | W44 | X44 | Y44 | Z44 | AA44 | AB44 | AC44 | AD44 | AE44 | AF44 | AG44 | AH44 | AI44 | AJ44 | AK44 | AL44 | AM44 | AN44 |
| A45 | B45 | C45 | D45 | E45 | F45 | G45 | H45 | I45 | J45 | K45 | L45 | M45 | N45 | O45 | P45 | Q45 | R45 | S45 | T45 | U45 | V45 | W45 | X45 | Y45 | Z45 | AA45 | AB45 | AC45 | AD45 | AE45 | AF45 | AG45 | AH45 | AI45 | AJ45 | AK45 | AL45 | AM45 | AN45 |
| A46 | B46 | C46 | D46 | E46 | F46 | G46 | H46 | I46 | J46 | K46 | L46 | M46 | N46 | O46 | P46 | Q46 | R46 | S46 | T46 | U46 | V46 | W46 | X46 | Y46 | Z46 | AA46 | AB46 | AC46 | AD46 | AE46 | AF46 | AG46 | AH46 | AI46 | AJ46 | AK46 | AL46 | AM46 | AN46 |
| A47 | B47 | C47 | D47 | E47 | F47 | G47 | H47 | I47 | J47 | K47 | L47 | M47 | N47 | O47 | P47 | Q47 | R47 | S47 | T47 | U47 | V47 | W47 | X47 | Y47 | Z47 | AA47 | AB47 | AC47 | AD47 | AE47 | AF47 | AG47 | AH47 | AI47 | AJ47 | AK47 | AL47 | AM47 | AN47 |
| A48 | B48 | C48 | D48 | E48 | F48 | G48 | H48 | I48 | J48 | K48 | L48 | M48 | N48 | O48 | P48 | Q48 | R48 | S48 | T48 | U48 | V48 | W48 | X48 | Y48 | Z48 | AA48 | AB48 | AC48 | AD48 | AE48 | AF48 | AG48 | AH48 | AI48 | AJ48 | AK48 | AL48 | AM48 | AN48 |
| A49 | B49 | C49 | D49 | E49 | F49 | G49 | H49 | I49 | J49 | K49 | L49 | M49 | N49 | O49 | P49 | Q49 | R49 | S49 | T49 | U49 | V49 | W49 | X49 | Y49 | Z49 | AA49 | AB49 | AC49 | AD49 | AE49 | AF49 | AG49 | AH49 | AI49 | AJ49 | AK49 | AL49 | AM49 | AN49 |
| A50 | B50 | C50 | D50 | E50 | F50 | G50 | H50 | I50 | J50 | K50 | L50 | M50 | N50 | O50 | P50 | Q50 | R50 | S50 | T50 | U50 | V50 | W50 | X50 | Y50 | Z50 | AA50 | AB50 | AC50 | AD50 | AE50 | AF50 | AG50 | AH50 | AI50 | AJ50 | AK50 | AL50 | AM50 | AN50 |
| A51 | B51 | C51 | D51 | E51 | F51 | G51 | H51 | I51 | J51 | K51 | L51 | M51 | N51 | O51 | P51 | Q51 | R51 | S51 | T51 | U51 | V51 | W51 | X51 | Y51 | Z51 | AA51 | AB51 | AC51 | AD51 | AE51 | AF51 | AG51 | AH51 | AI51 | AJ51 | AK51 | AL51 | AM51 | AN51 |
| A52 | B52 | C52 | D52 | E52 | F52 | G52 | H52 | I52 | J52 | K52 | L52 | M52 | N52 | O52 | P52 | Q52 | R52 | S52 | T52 | U52 | V52 | W52 | X52 | Y52 | Z52 | AA52 | AB52 | AC52 | AD52 | AE52 | AF52 | AG52 | AH52 | AI52 | AJ52 | AK52 | AL52 | AM52 | AN52 |
| A53 | B53 | C53 | D53 | E53 | F53 | G53 | H53 | I53 | J53 | K53 | L53 | M53 | N53 | O53 | P53 | Q53 | R53 | S53 | T53 | U53 | V53 | W53 | X53 | Y53 | Z53 | AA53 | AB53 | AC53 | AD53 | AE53 | AF53 | AG53 | AH53 | AI53 | AJ53 | AK53 | AL53 | AM53 | AN53 |
| A54 | B54 | C54 | D54 | E54 | F54 | G54 | H54 | I54 | J54 | K54 | L54 | M54 | N54 | O54 | P54 | Q54 | R54 | S54 | T54 | U54 | V54 | W54 | X54 | Y54 | Z54 | AA54 | AB54 | AC54 | AD54 | AE54 | AF54 | AG54 | AH54 | AI54 | AJ54 | AK54 | AL54 | AM54 | AN54 |
| A55 | B55 | C55 | D55 | E55 | F55 | G55 | H55 | I55 | J55 | K55 | L55 | M55 | N55 | O55 | P55 | Q55 | R55 | S55 | T55 | U55 | V55 | W55 | X55 | Y55 | Z55 | AA55 | AB55 | AC55 | AD55 | AE55 | AF55 | AG55 | AH55 | AI55 | AJ55 | AK55 | AL55 | AM55 | AN55 |
| A56 | B56 | C56 | D56 | E56 | F56 | G56 | H56 | I56 | J56 | K56 | L56 | M56 | N56 | O56 | P56 | Q56 | R56 | S56 | T56 | U56 | V56 | W56 | X56 | Y56 | Z56 | AA56 | AB56 | AC56 | AD56 | AE56 | AF56 | AG56 | AH56 | AI56 | AJ56 | AK56 | AL56 | AM56 | AN56 |
| A57 | B57 | C57 | D57 | E57 | F57 | G57 | H57 | I57 | J57 | K57 | L57 | M57 | N57 | O57 | P57 | Q57 | R57 | S57 | T57 | U57 | V57 | W57 | X57 | Y57 | Z57 | AA57 | AB57 | AC57 | AD57 | AE57 | AF57 | AG57 | AH57 | AI57 | AJ57 | AK57 | AL57 | AM57 | AN57 |
| A58 | B58 | C58 | D58 | E58 | F58 | G58 | H58 | I58 | J58 | K58 | L58 | M58 | N58 | O58 | P58 | Q58 | R58 | S58 | T58 | U58 | V58 | W58 | X58 | Y58 | Z58 | AA58 | AB58 | AC58 | AD58 | AE58 | AF58 | AG58 | AH58 | AI58 | AJ58 | AK58 | AL58 | AM58 | AN58 |
| A59 | B59 | C59 | D59 | E59 | F59 | G59 | H59 | I59 | J59 | K59 | L59 | M59 | N59 | O59 | P59 | Q59 | R59 | S59 | T59 | U59 | V59 | W59 | X59 | Y59 | Z59 | AA59 | AB59 | AC59 | AD59 | AE59 | AF59 | AG59 | AH59 | AI59 | AJ59 | AK59 | AL59 | AM59 | AN59 |
| A60 | B60 | C60 | D60 | E60 | F60 | G60 | H60 | I60 | J60 | K60 | L60 | M60 | N60 | O60 | P60 | Q60 | R60 | S60 | T60 | U60 | V60 | W60 | X60 | Y60 | Z60 | AA60 | AB60 | AC60 | AD60 | AE60 | AF60 | AG60 | AH60 | AI60 | AJ60 | AK60 | AL60 | AM60 | AN60 |
| A61 | B61 | C61 | D61 | E61 | F61 | G61 | H61 | I61 | J61 | K61 | L61 | M61 | N61 | O61 | P61 | Q61 | R61 | S61 | T61 | U61 | V61 | W61 | X61 | Y61 | Z61 | AA61 | AB61 | AC61 | AD61 | AE61 | AF61 | AG61 | AH61 | AI61 | AJ61 | AK61 | AL61 | AM61 | AN61 |
| A62 | B62 | C62 | D62 | E62 | F62 | G62 | H62 | I62 | J62 | K62 | L62 | M62 | N62 | O62 | P62 | Q62 | R62 | S62 | T62 | U62 | V62 | W62 | X62 | Y62 | Z62 | AA62 | AB62 | AC62 | AD62 | AE62 | AF62 | AG62 | AH62 | AI62 | AJ62 | AK62 | AL62 | AM62 | AN62 |
| A63 | B63 | C63 | D63 | E63 | F63 | G63 | H63 | I63 | J63 | K63 | L63 | M63 | N63 | O63 | P63 | Q63 | R63 | S63 | T63 | U63 | V63 | W63 | X63 | Y63 | Z63 | AA63 | AB63 | AC63 | AD63 | AE63 | AF63 | AG63 | AH63 | AI63 | AJ63 | AK63 | AL63 | AM63 | AN63 |
| A64 | B64 | C64 | D64 | E64 | F64 | G64 | H64 | I64 | J64 | K64 | L64 | M64 | N64 | O64 | P64 | Q64 | R64 | S64 | T64 | U64 | V64 | W64 | X64 | Y64 | Z64 | AA64 | AB64 | AC64 | AD64 | AE64 | AF64 | AG64 | AH64 | AI64 | AJ64 | AK64 | AL64 | AM64 | AN64 |
| A65 | B65 | C65 | D65 | E65 | F65 | G65 | H65 | I65 | J65 | K65 | L65 | M65 | N65 | O65 | P65 | Q65 | R65 | S65 | T65 | U65 | V65 | W65 | X65 | Y65 | Z65 | AA65 | AB65 | AC65 | AD65 | AE65 | AF65 | AG65 | AH65 | AI65 | AJ65 | AK65 | AL65 | AM65 | AN65 |
| A66 | B66 | C66 | D66 | E66 | F66 | G66 | H66 | I66 | J66 | K66 | L66 | M66 | N66 | O66 | P66 | Q66 | R66 | S66 | T66 | U66 | V66 | W66 | X66 | Y66 | Z66 | AA66 | AB66 | AC66 | AD66 | AE66 | AF66 | AG66 | AH66 | AI66 | AJ66 | AK66 | AL66 | AM66 | AN66 |
| A67 | B67 | C67 | D67 | E67 | F67 | G67 | H67 | I67 | J67 | K67 | L67 | M67 | N67 | O67 | P67 | Q67 | R67 | S67 | T67 | U67 | V67 | W67 | X67 | Y67 | Z67 | AA67 | AB67 | AC67 | AD67 | AE67 | AF67 | AG67 | AH67 | AI67 | AJ67 | AK67 | AL67 | AM67 | AN67 |
| A68 | B68 | C68 | D68 | E68 | F68 | G68 | H68 | I68 | J68 | K68 | L68 | M68 | N68 | O68 | P68 | Q68 | R68 | S68 | T68 | U68 | V68 | W68 | X68 | Y68 | Z68 | AA68 | AB68 | AC68 | AD68 | AE68 | AF68 | AG68 | AH68 | AI68 | AJ68 | AK68 | AL68 | AM68 | AN68 |
| A69 | B69 | C69 | D69 | E69 | F69 | G69 | H69 | I69 | J69 | K69 | L69 | M69 | N69 | O69 | P69 | Q69 | R69 | S69 | T69 | U69 | V69 | W69 | X69 | Y69 | Z69 | AA69 | AB69 | AC69 | AD69 | AE69 | AF69 | AG69 | AH69 | AI69 | AJ69 | AK69 | AL69 | AM69 | AN69 |
| A70 | B70 | C70 | D70 | E70 | F70 | G70 | H70 | I70 | J70 | K70 | L70 | M70 | N70 | O70 | P70 | Q70 | R70 | S70 | T70 | U70 | V70 | W70 | X70 | Y70 | Z70 | AA70 | AB70 | AC70 | AD70 | AE70 | AF70 | AG70 | AH70 | AI70 | AJ70 | AK70 | AL70 | AM70 | AN70 |
| A71 | B71 | C71 | D71 | E71 | F71 | G71 | H71 | I71 | J71 | K71 | L71 | M71 | N71 | O71 | P71 | Q71 | R71 | S71 | T71 | U71 | V71 | W71 | X71 | Y71 | Z71 | AA71 | AB71 | AC71 | AD71 | AE71 | AF71 | AG71 | AH71 | AI71 | AJ71 | AK71 | AL71 | AM71 | AN71 |
| A72 | B72 | C72 | D72 | E72 | F72 | G72 | H72 | I72 | J72 | K72 | L72 | M72 | N72 | O72 | P72 | Q72 | R72 | S72 | T72 | U72 | V72 | W72 | X72 | Y72 | Z72 | AA72 | AB72 | AC72 | AD72 | AE72 | AF72 | AG72 | AH72 | AI72 | AJ72 | AK72 | AL72 | AM72 | AN72 |
| A73 | B73 | C73 | D73 | E73 | F73 | G73 | H73 | I73 | J73 | K73 | L73 | M73 | N73 | O73 | P73 | Q73 | R73 | S73 | T73 | U73 | V73 | W73 | X73 | Y73 | Z73 | AA73 | AB73 | AC73 | AD73 | AE73 | AF73 | AG73 | AH73 | AI73 | AJ73 | AK73 | AL73 | AM73 | AN73 |
| A74 | B74 | C74 | D74 | E74 | F74 | G74 | H74 | I74 | J74 | K74 | L74 | M74 | N74 | O74 | P74 | Q74 | R74 | S74 | T74 | U74 | V74 | W74 | X74 | Y74 | Z74 | AA74 | AB74 | AC74 | AD74 | AE74 | AF74 | AG74 | AH74 | AI74 | AJ74 | AK74 | AL74 | AM74 | AN74 |
| A75 | B75 | C75 | D75 | E75 | F75 | G75 | H75 | I75 | J75 | K75 | L75 | M75 | N75 | O75 | P75 | Q75 | R75 | S75 | T75 | U75 | V75 | W75 | X75 | Y75 | Z75 | AA75 | AB75 | AC75 | AD75 | AE75 | AF75 | AG75 | AH75 | AI75 | AJ75 | AK75 | AL75 | AM75 | AN75 |
| A76 | B76 | C76 | D76 | E76 | F76 | G76 | H76 | I76 | J76 | K76 | L76 | M76 | N76 | O76 | P76 | Q76 | R76 | S76 | T76 | U76 | V76 | W76 | X76 | Y76 | Z76 | AA76 | AB76 | AC76 | AD76 | AE76 | AF76 | AG76 | AH76 | AI76 | AJ76 | AK76 | AL76 | AM76 | AN76 |
| A77 | B77 | C77 | D77 | E77 | F77 | G77 | H77 | I77 | J77 | K77 | L77 | M77 | N77 | O77 | P77 | Q77 | R77 | S77 | T77 | U77 | V77 | W77 | X77 | Y77 | Z77 | AA77 | AB77 | AC77 | AD77 | AE77 | AF77 | AG77 | AH77 | AI77 | AJ77 | AK77 | AL77 | AM77 | AN77 |
| A78 | B78 | C78 | D78 | E78 | F78 | G78 | H78 | I78 | J78 | K78 | L78 | M78 | N78 | O78 | P78 | Q78 | R78 | S78 | T78 | U78 | V78 | W78 | X78 | Y78 | Z78 | AA78 | AB78 | AC78 | AD78 | AE78 | AF78 | AG78 | AH78 | AI78 | AJ78 | AK78 | AL78 | AM78 | AN78 |
| A79 | B79 | C79 | D79 | E79 | F79 | G79 | H79 | I79 | J79 | K79 | L79 | M79 | N79 | O79 | P79 | Q79 | R79 | S79 | T79 | U79 | V79 | W79 | X79 | Y79 | Z79 | AA79 | AB79 | AC79 | AD79 | AE79 | AF79 | AG79 | AH79 | AI79 | AJ79 | AK79 | AL79 | AM79 | AN79 |
| A80 | B80 | C80 | D80 | E80 | F80 | G80 | H80 | I80 | J80 | K80 | L80 | M80 | N80 | O80 | P80 | Q80 | R80 | S80 | T80 | U80 | V80 | W80 | X80 | Y80 | Z80 | AA80 | AB80 | AC80 | AD80 | AE80 | AF80 | AG80 | AH80 | AI80 | AJ80 | AK80 | AL80 | AM80 | AN80 |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+------+------+------+------+------+------+------+------+------+------+------+------+------+

Code

Private Sub PopularListView()

    'Declaração de variáveis
    Dim wksOrigem As Worksheet
    Dim rData As Range
    Dim rCell As Range
    Dim LstItem As ListItem
    Dim linCont As Long
    Dim colCont As Long
    Dim i As Long
    Dim j As Long

    'Definição da planilha de origem
    Set wksOrigem = Worksheets("BANCO")

    'Definição do range de origem
    Set rData = wksOrigem.Range("A7").CurrentRegion

    'Adicionar cabeçalho no listview com laço de repetição 'For'
    For Each rCell In rData.Rows(1).Cells
        Me.ListV_P.ColumnHeaders.Add Text:=rCell.Value, Width:=90
    Next rCell

    'Alimentar variável linCont com número de linhas do intervalo fonte
    linCont = rData.Rows.Count

    'Alimentar variável colCont com número de linhas do intervalo fonte
    colCont = rData.Columns.Count

    'Popular o ListView
    For i = 2 To linCont
        Set LstItem = Me.ListV_P.ListItems.Add(Text:=rData(i, 1).Value)
        For j = 2 To colCont
            LstItem.ListSubItems.Add Text:=rData(i, j).Value
        Next j
    Next i

End Sub
Private Sub UserForm_Initialize()

    'Ajustes de algumas propriedades importantes do ListView
    With Me.ListV_P
        .Gridlines = True                        'linhas de grade visíveis (true)
        .HideColumnHeaders = False               'False para cabeçalho visível e True para invisível
        .View = lvwReport                        'Ajustar visualização do listview
    End With
    'se quiser detalhes da propriedade .view consulte: https://msdn.microsoft.com/en-us/library/aa733652(v=vs.60).aspx)

    'Chamar o procedimento para popular o Listview1
    Call PopularListView

End Sub

Upshot

Resultado

Browser other questions tagged

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