1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| Sub DécoupageRRH()
Dim aa, rh, ln, RRH(), plgET As Range, chD$, k%, n&, i&, d As Object, wsME As Worksheet, wsDATA As Worksheet, wsDECOUP As Worksheet
With ThisWorkbook
chD = .Path & "\"
Set wsME = .Worksheets("Mode d'emploi")
Set wsDATA = .Worksheets("Données")
Set wsDECOUP = .Worksheets("Découpage fichiers")
End With
With wsDATA
i = .Range("A" & .Rows.Count).End(xlUp).Row
If i <= 15 Then Exit Sub
k = .Cells.SpecialCells(xlCellTypeLastCell).Column
aa = .Range("A15:A" & i).Resize(, k).Value
Set plgET = .Range("A1:A14").Resize(, k)
End With
chD = ThisWorkbook.Path & "\"
Set d = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(aa)
d(aa(i, 1)) = d(aa(i, 1)) & ";" & i
Next i
Application.ScreenUpdating = False
For Each rh In d.keys
ln = Split(d(rh), ";"): n = UBound(ln)
ReDim RRH(1 To n)
For i = 1 To n
RRH(i) = WorksheetFunction.Index(aa, CInt(ln(i)), 0)
Next i
With Workbooks.Add(xlWBATWorksheet)
.Worksheets(1).Name = ("Données")
With .Worksheets(1)
plgET.Copy .Range("A1")
With .Range("A15").Resize(n, k)
.Value = WorksheetFunction.Transpose(WorksheetFunction.Transpose(RRH))
.Borders.Weight = xlThin
End With
End With
wsME.Copy before:=.Worksheets(1)
wsDECOUP.Copy before:=.Worksheets(1)
.SaveAs chD & rh & ".xlsx"
.Close
End With
Next rh
MsgBox "Découpage du fichier terminé !"
End Sub |
Partager