Notifications
Clear all

MACRO PARA REESTRUTURAR UMA BASE DE DADOS

2 Posts
2 Usuários
0 Reactions
881 Visualizações
(@cazevedo)
Posts: 0
New Member
Topic starter
 

Bom dia pessoal, estou precisando reestruturar uma base de dados. Estou enviando o arquivo anexo, e o que eu precisaria era uma macro que transformasse os dados da plan1 nos dados da plan2. Alguem poderia me ajudar?

Obrigado.

 
Postado : 27/06/2017 7:06 am
(@osvaldomp)
Posts: 857
Prominent Member
 

Experimente:

Sub RearranjaDados()
 Dim k As Long, LR As Long, m As Long
  If Sheets("Plan2").[A2] <> "" Then
   Sheets("Plan2").Range("A2:J" & Sheets("Plan2").Cells(Rows.Count, 1).End(3).Row).Value = ""
  End If
   For k = 2 To Cells(Rows.Count, 1).End(3).Row
    m = Application.CountIf([A:A], Cells(k, 1))
    With Sheets("Plan2")
     LR = .Cells(.Rows.Count, 1).End(3).Row
     .Cells(LR + 1, 1).Resize(, 3).Value = Cells(k, 1).Resize(, 3).Value
     .Cells(LR + 1, 4) = m
     .Cells(LR + 1, 5).Resize(, m).Value = Application.Transpose(Cells(k, 4).Resize(m).Value)
     k = k + m - 1
    End With
   Next k
End Sub
 
Postado : 27/06/2017 1:00 pm