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
| Option Explicit
Option Base 1
Sub ConversionTableau()
Dim DataA() As Variant, DataB() As Variant, kR As Long, kC As Long, k As Long
DataA = Worksheets("Initial").UsedRange.Value '--- suppose qu'il n'y a pas de données en dehors du tableau
kR = UBound(DataA, 1) '--- nb de lignes
kC = UBound(DataA, 2) '--- nb de colonnes
k = (kR - 1) * (kC - 1) + 1 '--- nb de données (mots)
ReDim DataB(k, 4)
DataB(1, 1) = "Id"
DataB(1, 2) = "Thème"
DataB(1, 3) = "Rang"
DataB(1, 4) = "Mot"
k = 1
For kR = 2 To UBound(DataA, 1) '--- les lignes
For kC = 2 To UBound(DataA, 2) '--- les colonnes
k = k + 1
DataB(k, 1) = DataA(kR, 1)
DataB(k, 2) = Left(DataA(1, kC), Len(DataA(1, kC)) - 4)
DataB(k, 3) = 1 + (kC + 2) Mod 4
DataB(k, 4) = DataA(kR, kC)
Next kC
Next kR
Worksheets("Final").Select
Worksheets("Final").Cells.ClearContents
Worksheets("Final").Range("A1:D" & k) = DataB
End Sub |
Partager