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
| Sub Transpose()
Dim CellFrom As Range, CellTo As Range
Dim r As Single, FindPosition As Single, cCel As Single
Dim FindTable As Range
cCel = 1 ' Compteur
With ThisWorkbook
Set CellFrom = .Worksheets("Feuil1").Range("A2")
Set CellTo = .Worksheets("Feuil2").Range("B2")
End With
For r = 0 To CellFrom.End(xlDown).Row - 2
With CellTo
.Offset(r + 1, 0) = CellFrom.Offset(r, 0)
Set FindTable = Range(Cells(.Row, .Column + 1), Cells(.Row, .Column + 1 + cCel))
On Error GoTo ErrorHandler
FindPosition = Application.WorksheetFunction.Match(CellFrom.Offset(r, 1), FindTable, False)
If FindPosition = 0 Then FindPosition = cCel: cCel = cCel + 1
On Error GoTo 0
.Offset(.Row - 2, FindPosition) = CellFrom.Offset(r, 1)
.Offset(r + 1, FindPosition) = "x"
End With
Next
Exit Sub
ErrorHandler:
If Err.Number = 1004 Then FindPosition = 0: Resume Next Else MsgBox "Problème"
End Sub |
Partager