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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| Const ForReading = 1, ForWriting = 2
Dim oFso, f
Set oFso = CreateObject("Scripting.FileSystemObject")
Set f = oFso.OpenTextFile("C:\Users\Monique\Downloads\Fichier à importer (1).csv", ForReading)
ln=-1
cl=0
while Not f.AtEndOfStream '1ère itération pour définir les limites du tableau
ln=ln+1 'définition indice lignes
Tab=Split(f.ReadLine,";")
If cl < UBound(Tab) Then cl = UBound(Tab)
Wend
f.Close
'MsgBox "indice lignes : " & ln+1 & "indice colonnes :" & cl+1
Dim Tab2()
ReDim Tab2(ln,cl)
Set f = oFso.OpenTextFile("C:\Users\Monique\Downloads\Fichier à importer (1).csv", ForReading)
i=0
while Not f.AtEndOfStream ' 2ème itération pour remplir le tableau Tab2
Tab = Split(f.ReadLine,";")
For j = 0 to UBound(Tab)
Tab2(i,j) = Tab(j)
Next
i=i+1
Wend
f.Close
Dim Tab3()
ReDim Tab3(ln-1,cl)
For i=1 to UBound(Tab2,1) ' copie tout de tab2 à tab 3 sauf 1ere ligne marche
For j=0 to Ubound(Tab2,2)'oui
Tab3(i-1,j)=Tab2(i,j)'oui
Next
Next
For i=0 to UBound(Tab3,1) ' on copie dans tab3 les clé dans la première colonne de chaque ligne
For j=0 to Ubound(Tab3,2)
Tab3(i,0)=Tab3(i,3)+Tab3(i,5)+Tab3(i,6)+Tab3(i,9)
Next
Next
For i=0 to Ubound(Tab3,1) ' on décale tous les mois vers la gauche
For j=1 to Ubound(Tab3,2)-20
Tab3(i,j)=Tab3(i,j+20)
Next
Next
Dim fsot, ft
Set fsot = CreateObject("Scripting.FileSystemObject")
Set ft = fsot.OpenTextFile("C:\Users\Monique\Downloads\lololololololo.txt", 2,true)
Set objKeysDictionnary = CreateObject("Scripting.Dictionary") 'Création du dictionnaire contenant les clés
objKeysDictionnary.CompareMode = 1 'Mode de comparaison : texte
For i=0 to Ubound(Tab3,1) ' Pour chaque occurence du tableau Tab3
If objKeysDictionnary.Exists(Tab3(i,0)) Then
objKeysDictionnary.Item(Tab3(i,0)) = objKeysDictionnary.Item(Tab3(i,0)) + Tab3(i,1) 'Si la clé a déjà été trouvée, ajout des valeurs
Else
objKeysDictionnary.Add Tab3(i,0), Tab3(i,1) 'Sinon ajout de la clé au dictionnaire
End If
Next
i=0
For Each strKey In objKeysDictionnary.Keys 'Pour chaque clé contenue dans le dictionnaire
i=i+1
Next
Dim Tab4()
ReDim Tab4(i-1,13)
i=0
For Each strKey In objKeysDictionnary.Keys 'Pour chaque clé contenue dans le dictionnaire
Tab4(i,0)=strKey
i=i+1
Next
For i=0 to Ubound(Tab3,1)
For j=0 to Ubound(Tab4,1)
If Tab4(j,0)=Tab3(i,0) Then
Tab4(j,1)=Tab4(j,1)+Tab3(i,1)
Tab4(j,2)=Tab4(j,2)+Tab3(i,2)
Tab4(j,3)=Tab4(j,3)+Tab3(i,3)
Tab4(j,4)=Tab4(j,4)+Tab3(i,4)
Tab4(j,5)=Tab4(j,5)+Tab3(i,5)
Tab4(j,6)=Tab4(j,6)+Tab3(i,6)
Tab4(j,7)=Tab4(j,7)+Tab3(i,7)
Tab4(j,8)=Tab4(j,8)+Tab3(i,8)
Tab4(j,9)=Tab4(j,9)+Tab3(i,9)
Tab4(j,10)=Tab4(j,10)+Tab3(i,10)
Tab4(j,11)=Tab4(j,11)+Tab3(i,11)
Tab4(j,12)=Tab4(j,12)+Tab3(i,12)
End If
Next
Next
m=0
Redim Preserve Tab4(Ubound(Tab4,1),13) ' pour le bon nombre de colonnes
For i=0 to UBound(Tab4,1) ' copie de tab3 dans le fichier et marche
For j=0 to UBound(Tab4,2)
If m < UBound(Tab4,2) Then
ft.write(Tab4(i,j) & " ")
m=m+1
Else
ft.write(Tab4(i,j) & vbcrlf)
m=0
End If
Next
Next |