Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
Por Wascesar0412
#51422
Boa tarde Pessoal,

Estou aprendendo a suar o VBA, e estou com dificuldades de realizar um loop dentro de um listbox.

Na realidade preciso percorrer todo os dados dentro de um listbox e imprimir conforme por campo.

tenho no listbox os campos fornecedores e produtos.

Preciso imprimir a relação de cada produto vinculado ao seu fornecedor.

segue a rotina que utilizo

Private Sub CommandButton2_Click()
On Error Resume Next
Dim ListaFornecedores As New Collection, Linha
Dim I As Integer
Dim T As Integer
Dim XYZ() As String

TotalFor = cmbFornecedor.ListCount - 1
ReDim XYZ(TotalFor) As String

'// Coletando todos os Fornecedores
Dim Fornecedores() As String
ReDim Fornecedores(lstProdutos.ListCount - 1) As String


For T = 0 To cmbFornecedor.ListCount - 1
XYZ(T) = cmbFornecedor.List(T, 0)
For I = 0 To lstProdutos.ListCount - 1
If (XYZ(T) = lstProdutos.List(I, 2)) Then
Fornecedores(I) = XYZ(T)
End If
Next I
Next T

'//Eliminando os duplicados.
For Each Linha In Fornecedores
ListaFornecedores.Add Linha, Linha
Next
For L = 0 To ListaFornecedores.Count
ForNome = ListaFornecedores(L)

'// Salvando na Planilha Auxiliar
With Sheets("Auxiliar")
.Select
Range("B2").Value = txtCodCompra.Text
Range("B3").Value = ForNome
Range("D2").Value = Date
Range("A7").Select

For I = 0 To lstProdutos.ListCount - 1
If ForNome = lstProdutos.List(I, 2) Then
ActiveCell.Offset(I, 0).Value = lstProdutos.List(I, 0) ' Código
ActiveCell.Offset(I, 1).Value = lstProdutos.List(I, 1) ' Nome
ActiveCell.Offset(I, 2).Value = Format(lstProdutos.List(I, 3), "000") ' Quantidade
ActiveCell.Offset(I, 3).Value = Format(lstProdutos.List(I, 4), "###,##0.00") ' Valor únitario
ActiveCell.Offset(I, 4).Value = Format(lstProdutos.List(I, 5), "###,##0.00") ' Valor Total
Else
' Tenho que deletar as linhas e não limpar
ActiveCell.Offset(I, 0).Value = Empty
ActiveCell.Offset(I, 1).Value = Empty
ActiveCell.Offset(I, 2).Value = Empty
ActiveCell.Offset(I, 3).Value = Empty
ActiveCell.Offset(I, 4).Value = Empty
End If
Next I
End With

Call Imprimir

Next L

End Sub


Deste de já agradeço .
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord