Transformation d'une liste de cours en ligne en une liste par colonne
l
Bonjour, j'ai une liste de personnes qui ont suivi un ou plusieurs cours. j'aimerais avoir les même données mais avec une seule ligne par personne, et le nom des cours en colonne.
J'ai attaché un fichier qui illustre ma demande.
Merci d'avance pour vos retours :-) Belle journée
a
Bonjour, je viens de poster une question à peu près similaire quelques minutes après vous. Je pense que les réponses apportées seront utiles à l'autre. Bonne recherche. Alexis
Bonjour alexisjbd , lipfon
Vois ceci :
Option Explicit
Sub test()
Dim a, w(), i As Long, j As Long, n As Long, col As Byte, txt As String, dico As Object
Set dico = CreateObject("Scripting.Dictionary")
dico.comparemode = 1
a = Sheets("Cours").Range("A1").CurrentRegion.Value
col = UBound(a, 2): n = 1
For i = 2 To UBound(a, 1)
txt = Join(Array(a(i, 1), a(i, 2)), Chr(2))
If Not dico.exists(txt) Then
n = n + 1: dico(txt) = VBA.Array(n, col)
For j = 1 To col
a(n, j) = a(i, j)
Next
Else
w = dico(txt): w(1) = w(1) + 2
If UBound(a, 2) < w(1) Then
ReDim Preserve a(1 To UBound(a, 1), 1 To w(1))
End If
For j = 1 To 2
a(w(0), w(1) - 2 + j) = a(i, j + 2)
Next
dico(txt) = w
End If
Next
Application.ScreenUpdating = False
With Sheets.Add().Cells(1).Resize(n, UBound(a, 2))
.Value = a
If UBound(a, 2) > col Then
With .Offset(, 2).Resize(1, 2)
.AutoFill .Resize(, UBound(a, 2) - col + 2)
End With
End If
.Font.Name = "calibri"
.Font.Size = 10
.VerticalAlignment = xlCenter
.Borders(xlInsideVertical).Weight = xlThin
.BorderAround Weight:=xlThin
With .Rows(1)
.Font.Size = 11
.BorderAround Weight:=xlThin
With .Offset(, 2).Resize(, .Columns.Count - 2)
.Interior.ColorIndex = 44
End With
End With
With .Columns(1).Offset(1).Resize(.Rows.Count - 1)
.Interior.ColorIndex = 19
End With
With .Offset(1).Resize(.Rows.Count - 1)
For i = 4 To .Columns.Count Step 2
.Columns(i).NumberFormat = "mmm-yy"
Next
End With
.Columns.ColumnWidth = 15
End With
Set dico = Nothing
Application.ScreenUpdating = True
End Sub
klin89