Notifications
Clear all

Repetir Registro X vezes

4 Posts
1 Usuários
0 Reactions
474 Visualizações
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Ola

Tenho uma planilha com nomes de clientes e um campo quantidade para cada um

Exemplo:

Cliente Quantidade
AAAA 2
RRRRR 3
BBBB 1
DDDD 2

Gostaria de repetir o registro CLIENTE o numero de vezes da quantidade, por exemplo o cliente AAAA tem quantidade 2
Então iria repetir esse registro 2 vezes

Alguém pode me ajudar?

 
Postado : 01/03/2013 2:36 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Boa noite!!

Pode ser via VBA?

Sub AleVBA_Repetir()
Application.ScreenUpdating = False
Dim LastRow&, NextRow&, cell As Range
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
Columns(3).Clear
NextRow = 2
Range("C1").Value = "Resultado_AleVBA"
For Each cell In Range(Cells(2, 1), Cells(LastRow, 1)).SpecialCells(2)
cell.Copy Range(Cells(NextRow, 3), Cells(NextRow + cell.Offset(0, 1).Value - 1, 3))
NextRow = Cells(Rows.Count, 3).End(xlUp).Row + 1
Next cell
Application.ScreenUpdating = True
End Sub
 
Postado : 01/03/2013 2:49 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Sem maiores detalhes segue mais uma opção; veja se atende

Sub Replicar()
Dim lastRow As Long, X As Long, Z As Long, T As Long, y As Long
    lastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Z = 2
For X = 2 To lastRow
    
     T = Cells(X, 2)
   For y = 1 To T
        Range("E" & Z) = Range("A" & X).Value
    Z = Z + 1
    Next
Next

End Sub
 
Postado : 01/03/2013 2:58 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Muito obrigado

Funcionou Perfeitamente

 
Postado : 04/03/2013 6:28 am