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 49 50 51 52 53 54 55 56 57 58 59 60
| Sub transposition()
Dim ligne As Integer, Period As Integer, Derperiod As Integer, Debid As Integer, Bas As Integer
Dim texte As String, E As String
Application.ScreenUpdating = False
Set ws = Sheets("INPUT")
Set dest = Sheets("resultat")
'dernière ligne
Bas = Cells(64000, 2).End(xlUp).Row
Debid = 2
ligne = 2
texte = ""
E = ";"
While Debid <= Bas
'recherche première id
While ws.Cells(Debid, 2) = "" And Debid <= Bas
Debid = Debid + 1
Wend
'parcours des id's courantes
While ws.Cells(Debid, 2) <> ""
'traitement des id's
Derperiod = ws.Cells(Debid, 10000).End(xlToLeft).Column
Period = 5
'parcours des périodes
While Period <= Derperiod
While ws.Cells(Debid, Period) = "" And Period <= Derperiod
Period = Period + 1 'colonne suivante
Wend
If ws.Cells(Debid, Period) <> "" Then
texte = texte & ws.Cells(Debid, 2) & E & ws.Cells(Debid, 3) & E & ws.Cells(1, Period) & E & ws.Cells(Debid, Period) & vbCrLf
'If ws.Cells(Debid, Period) <> "" Then
'traitement des périodes
'dest.Cells(ligne, 1) = ws.Cells(Debid, 2)
'dest.Cells(ligne, 2) = ws.Cells(Debid, 3)
'dest.Cells(ligne, 3) = ws.Cells(1, Period)
'dest.Cells(ligne, 4) = ws.Cells(Debid, Period)
Period = Period + 1
End If
ligne = ligne + 1 'ligne suivante
Wend
Debid = Debid + 1 'id suivante
Wend
Wend
Debug.Print texte
fichier = ThisWorkbook.Path & "\" & "transposition .txt"
x = FreeFile
Open fichier For Output As #x
Print #x, texte
Close #x
Application.ScreenUpdating = True
End Sub |
Partager