Notifications
Clear all

Repetir linha

13 Posts
1 Usuários
0 Reactions
2,142 Visualizações
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Bom dia!
Gostaria que no código a baixo ao invés de inserir linhas em branco conforme o nº informado na coluna, eu quero que repita as linhas inteiras.

Private Sub CommandButton1_Click()

Dim FirstRow As Long
Dim LastRow As Long
Dim iRow As Long
Dim wks As Worksheet

Set wks = ActiveSheet

With wks
FirstRow = 2
LastRow = .Cells(.Rows.Count, "a").End(xlUp).Row

For iRow = LastRow To FirstRow Step -1
With .Cells(iRow, "a")
If IsNumeric(.Value) Then
If .Value > 1 Then
.Offset(1, 0).Resize(.Value).EntireRow.Insert
End If
End If
End With
Next iRow
End With

End Sub

 
Postado : 21/07/2011 5:31 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Andre Seja Bem Vindo!

Não consigo ainda analisar um codigo apenas sem o arquivo, mas um dia chego lá.

Posta um modelo pra gente da uma olhada.

BLZ?

T+

 
Postado : 21/07/2011 7:05 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Segue planilha como modelo.
vlw

 
Postado : 21/07/2011 7:50 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 


Veja se esta alteração retorna como pretende...

If .Value > 1 Then
Rows(iRow).Copy
Rows(iRow + 1).Insert Shift:=xlDown
End If

 
Postado : 21/07/2011 8:18 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Até deu certo só repetiu a linha 1 vez, gostaria que repetisse a linha conforme o nº informado da célula.
Exemplo : se o nº da célula é 3 quero que repita 3 vezes a linha .

obrigado

 
Postado : 21/07/2011 8:46 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 


Veja agora:

Dim cont As Integer
Dim i As Integer

i = 1
.
.
.

If .Value > 1 Then
cont = .Value
Do While i <= cont
Rows(iRow).Copy
Rows(iRow + 1).Insert Shift:=xlDown
i = i + 1
Loop
i = 1
End If

 
Postado : 21/07/2011 10:28 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Vlw, muito obrigado. Porém além de repetir as linhas esta abrindo linhas em branco.
Poderia me dizer como faço para abrir as linhas em branco.
To mandando o anexo, veja como ficou.

obrigado

 
Postado : 21/07/2011 11:07 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Desculpe não qro linhas em branco , qro exclui-la, e se possivel abrir a quantidade menos 1,(exemplo se na célula é 5, qro que insira apenas 4 linhas repetidas.

abraço

 
Postado : 21/07/2011 11:21 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 


Não são inseridas novas linhas e branco e sim mantidas as já existentes...
O ideal seria que não houvesse estas linhas na base de dados... mas vou pensar em algo...

Para inserir o valor da célula - 1:

cont = .Value - 1

 
Postado : 21/07/2011 11:57 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Ok, obrigado, se conseguir algo me passe por gentileza.
vlw

 
Postado : 21/07/2011 12:09 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Poderia passar o código inteiro pra mim.
obrigado.

 
Postado : 21/07/2011 1:53 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Poderia por gentileza me mandar o código completo.

abraço

 
Postado : 21/07/2011 2:16 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Por favor, no código abaixo como faço para que não repita a informação de um determinada coluna.

Private Sub CommandButton1_Click()

Dim FirstRow As Long
Dim LastRow As Long
Dim iRow As Long
Dim wks As Worksheet

Set wks = ActiveSheet

With wks
FirstRow = 2
LastRow = .Cells(.Rows.Count, "c").End(xlUp).Row

For iRow = LastRow To FirstRow Step -1
With .Cells(iRow, "c")
If IsNumeric(.Value) Then
If .Value > 1 Then
.Offset(1, 0).Resize(.Value).EntireRow.Insert

Dim cont As Integer
Dim i As Integer

i = 1

If .Value > 1 Then
cont = .Value - 1
Do While i <= cont
Rows(iRow).Copy
Rows(iRow + 1).Insert Shift:=xlDown
i = i + 1
Loop
i = 1
End If

End If
End If
End With
Next iRow
End With

End Sub

atenciosamente.

 
Postado : 22/07/2011 8:09 am