Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

Transformer ligne en colonne

infotun

XLDnaute Nouveau
Salut,

je voudrais faire une transformation sur des mots qui sont aligné le long d'une ligne
expemple:
1 mot1,mot2
2 mot3,mot4,mot5,mot6,mot7..etc
3 mot20,mot21
.
.
...etc

transformer:

1 mot1
1 mot2
2 mot3
2 mot4
2 mot5
2 mot6
2 mot7
..
3 mot20
3 mot21
...etc

ci-dessous une pièce jointe du fichier excel comme exemple.

merci pour votre aide
 

Pièces jointes

  • transformation.xls
    19.5 KB · Affichages: 105
  • transformation.xls
    19.5 KB · Affichages: 107
  • transformation.xls
    19.5 KB · Affichages: 104

kjin

XLDnaute Barbatruc
Re : Transformer ligne en colonne

Bonsoir,
Code:
Sub zozo()
Dim i As Long, j As Long, c As Range
For Each c In Range("B2:B" & Range("A65000").End(xlUp).Row)
    t = Split(c, ",")
    If UBound(t) > 0 Then
        For i = LBound(t) To UBound(t)
            j = j + 1
            Cells(j, 5) = t(i)
            Cells(j, 4) = c.Offset(0, -1)
        Next
    End If
Next

End Sub
A+
kjin
 

job75

XLDnaute Barbatruc
Re : Transformer ligne en colonne

Bonsoir infotun, kjin,

La macro est plus longue car elle fait aussi du formatage :

Code:
Sub Transformer()
Dim lig As Long, i As Long, j As Integer, tablo(), n As Long
Application.ScreenUpdating = False
lig = [A1].End(xlDown).Row 'dernière ligne
'---Détermination du tableau de valeurs---
For i = 2 To lig
  For j = 0 To UBound(Split(Cells(i, 2), ","))
    ReDim Preserve tablo(1, n)
    tablo(0, n) = Cells(i, 1)
    tablo(1, n) = Split(Cells(i, 2), ",")(j)
    n = n + 1
  Next
Next
'---Formatage---
Range(Cells(lig + 3, 1), Cells(65536, 2)).Clear
Columns(1).HorizontalAlignment = xlCenter
With Cells(lig + 3, 1).Resize(n, 2)
  .Borders(xlEdgeLeft).LineStyle = xlContinuous
  .Borders(xlEdgeTop).LineStyle = xlContinuous
  .Borders(xlEdgeBottom).LineStyle = xlContinuous
  .Borders(xlEdgeRight).LineStyle = xlContinuous
  .Borders(xlInsideVertical).LineStyle = xlContinuous
  .Borders(xlInsideHorizontal).LineStyle = xlContinuous
  '---Remplissage---
  .Value = Application.Transpose(tablo)
End With
End Sub

A+
 

Pièces jointes

  • transformation(1).zip
    12.6 KB · Affichages: 61
Dernière édition:

Discussions similaires

Réponses
14
Affichages
601
Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…