Option Explicit
Sub archivia()
Dim sh1 As Worksheet: Set sh1 = Worksheets("Foglio1")
Dim sh2 As Worksheet: Set sh2 = Worksheets("Foglio2")
Dim X, Ur, Y, Rg, Tot
Ur = sh1.Range("A" & Rows.Count).End(xlUp).Row
Rg = 3
Application.ScreenUpdating = False
For X = 1 To Ur
Tot = Application.WorksheetFunction.CountIf(sh1.Range("A:A"), sh1.Cells(X, 1).Value)
sh2.Cells(Rg, 1) = sh1.Cells(X, 1)
sh2.Cells(Rg, 2) = Rg - 2
For Y = 1 To Tot
Select Case sh1.Cells(X, 2)
Case "BA"
sh1.Range(sh1.Cells(X, 3), sh1.Cells(X, 7)).Copy
sh2.Cells(Rg, 3).PasteSpecial
Case "CA"
sh1.Range(sh1.Cells(X, 3), sh1.Cells(X, 7)).Copy
sh2.Cells(Rg, 8).PasteSpecial
Case "FI"
sh1.Range(sh1.Cells(X, 3), sh1.Cells(X, 7)).Copy
sh2.Cells(Rg, 13).PasteSpecial
Case "GE"
sh1.Range(sh1.Cells(X, 3), sh1.Cells(X, 7)).Copy
sh2.Cells(Rg, 18).PasteSpecial
Case "MI"
sh1.Range(sh1.Cells(X, 3), sh1.Cells(X, 7)).Copy
sh2.Cells(Rg, 23).PasteSpecial
Case "NA"
sh1.Range(sh1.Cells(X, 3), sh1.Cells(X, 7)).Copy
sh2.Cells(Rg, 28).PasteSpecial
Case "PA"
sh1.Range(sh1.Cells(X, 3), sh1.Cells(X, 7)).Copy
sh2.Cells(Rg, 33).PasteSpecial
Case "RM"
sh1.Range(sh1.Cells(X, 3), sh1.Cells(X, 7)).Copy
sh2.Cells(Rg, 38).PasteSpecial
Case "TR"
sh1.Range(sh1.Cells(X, 3), sh1.Cells(X, 7)).Copy
sh2.Cells(Rg, 43).PasteSpecial
Case "VE"
sh1.Range(sh1.Cells(X, 3), sh1.Cells(X, 7)).Copy
sh2.Cells(Rg, 48).PasteSpecial
Case "RN"
sh1.Range(sh1.Cells(X, 3), sh1.Cells(X, 7)).Copy
sh2.Cells(Rg, 53).PasteSpecial
End Select
If Y <> Tot Then X = X + 1
Next Y
Rg = Rg + 1
Next X
Application.ScreenUpdating = True
Set sh1 = Nothing
Set sh2 = Nothing
MsgBox "fatto"
End Sub |