ALAN
|
CAMAQUA RS - BRASIL
|
|
ENUNCIADA !
|
|
|
Postada em 31/03/2010 08:23 hs
Galera, tenho um Listview no VBA, que carrega os dados, mas na hora de gravar esses dados em outra planilha da erro de índex. O listview tem só duas colunas , ele ta puxando a segunda coluna como item de índex numero 1.Mas eu preciso puxar também os dados da primeira coluna.Já coloquei como índex : zero, um,..mas não grava.Dá Erro em Tempo de Execução’35600’ ‘Index out of bound’.Como fica a ordem correta de índex????Segue um trecho do código...
Private Sub UserForm_Initialize()
TotalRegistros = Nomes.UsedRange.Rows.Count TotalRegistros = Lancamentos.UsedRange.Rows.Count Call PreencheLista
End Sub Private Sub cmdGravar_Click()
With Lancamentos TotalRegistros = Lancamentos.UsedRange.Rows.Count 'TotalRegistros = Nomes.UsedRange.Rows.Count LinhaPlanilha = TotalRegistros + 1
Dim y As Integer y = LinhaPlanilha
For X = 1 To ListView1.ListItems.Count .Cells(y, 2) = ListView1.ListItems(X).ListSubItems.Item(1) 'aqui puxa os nomes para col B, ok .Cells(y, 1) = ListView1.ListItems(X).ListSubItems.Item(0) 'aqui da erro de "index out of bounds"
y = y + 1 Next X
End With
End Sub Private Sub PreencheLista() Dim startrow As Integer 'beginning of data Dim endrow As Integer 'end of data Dim pos As Integer 'rowno Dim lv_item As Integer 'listview item no Dim counting As Integer 'loopvariable to go through data
startrow = 2 endrow = xlMaxRow("NOMES") pos = 2 lv_item = 1
With ListView1 'gives me headers at the top .View = lvwReport 'defining the columnheaders '.Sorted = True '.SortKey = 1 With .ColumnHeaders .Clear '.Add , , "", 0 .Add , , "Matricula", 50 .Add , , "Nome", 180 End With '.Sorted = True '.SortKey = 1 .HideColumnHeaders = False .Appearance = ccFlat .FullRowSelect = True .Gridlines = True '.Sorted = True '.SortKey = 1 For counting = startrow To endrow .ListItems.Add , , Worksheets("NOMES").Range("A" & pos) .ListItems(lv_item).ListSubItems.Add , , Worksheets("NOMES").Range("B" & pos) lv_item = lv_item + 1 pos = pos + 1 Next counting End With
End Sub
|
|
|
|
ALAN
|
CAMAQUA RS - BRASIL
|
|
ENUNCIADA !
|
|
|
Postada em 31/03/2010 21:33 hs
Consegui pessoal, segue solução: .ListItems.Add , , Worksheets("NOMES").Range("A" & pos) 'INSERI A LINHA QUE SEGUE E RESOLVEU .ListItems(lv_item).ListSubItems.Add , , Worksheets("NOMES").Range("A" & pos) .ListItems(lv_item).ListSubItems.Add , , Worksheets("NOMES").Range("B" & pos) lv_item = lv_item + 1 pos = pos + 1 Next counting Valeu a atenção..
|
|
|
|