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és 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) dim d,i,t, Tab4 t = Tab3 Set d = CreateObject("Scripting.Dictionary") For I = 0 To UBound(Tab3) 'a d.Keys : b d.items if not d.Exists(t(i,0)) then d.add Tab3(i,0),i t(i,1) = Tab3(i,1) t(i,2) = Tab3(i,2) t(i,3) = Tab3(i,3) t(i,4) = Tab3(i,4) t(i,5) = Tab3(i,5) t(i,6) = Tab3(i,6) t(i,7) = Tab3(i,7) t(i,8) = Tab3(i,8) t(i,9) = Tab3(i,9) t(i,10) = Tab3(i,10) t(i,11) = Tab3(i,11) t(i,12) = Tab3(i,12) else ou = d(t(i,0)) t(ou,1) = cdbl(Tab3(ou,1)) + cdbl(Tab3(i,1)) t(ou,2) = cdbl(Tab3(ou,2)) + cdbl(Tab3(i,2)) t(ou,3) = cdbl(Tab3(ou,3)) + cdbl(Tab3(i,3)) t(ou,4) = cdbl(Tab3(ou,4)) + cdbl(Tab3(i,4)) t(ou,5) = cdbl(Tab3(ou,5)) + cdbl(Tab3(i,5)) t(ou,6) = cdbl(Tab3(ou,6)) + cdbl(Tab3(i,6)) t(ou,7) = cdbl(Tab3(ou,7)) + cdbl(Tab3(i,7)) t(ou,8) = cdbl(Tab3(ou,8)) + cdbl(Tab3(i,8)) t(ou,9) = cdbl(Tab3(ou,9)) + cdbl(Tab3(i,9)) t(ou,10) = cdbl(Tab3(ou,10)) + cdbl(Tab3(i,10)) t(ou,11) = cdbl(Tab3(ou,11)) + cdbl(Tab3(i,11)) t(ou,12) = cdbl(Tab3(ou,12)) + cdbl(Tab3(i,12)) t(i,0) = "" end if next redim Tab4(d.count-1,13) n = 0 for i = 0 to ubound(t) if t(i,0) <> "" then Tab4(n,0) t(i,0) : Tab4(n,1) t(i,1) : Tab4(n,2) = t(i,2) : Tab4(n,3) = t(i,3) : Tab4(n,4) = t(i,4) : Tab4(n,5) = t(i,5) : Tab4(n,6) = t(i,6) : Tab4(n,7) = t(i,7) : Tab4(n,8) = t(i,8) : Tab4(n,9) = t(i,9) : Tab4(n,10) = t(i,10) : Tab4(n,11) = t(i,11) : Tab4(n,12) = t(i,12) n = n + 1 end if next 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
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionMon problème ici relève du traitement de Tab3 en Tab4 et non pas à partir du CSV
dim tableau(3,2),d,i,t,j,n, resultat ' je "dresse un tableau tab3 (celui de travail) correctement tableau(0,0) = "clef1" tableau(0,1) = "6,2" tableau(0,2) = "2" tableau(1,0) = "clef2" tableau(1,1) = "2" tableau(1,2) = "-4,35" tableau(2,0) = "clef3" tableau(2,1) = "5" tableau(2,2) = "9" tableau(3,0) = "clef2" tableau(3,1) = "7" tableau(3,2) = "3" t = tableau Set d = CreateObject("Scripting.Dictionary") For I = 0 To UBound(tableau) 'a d.Keys : b d.items if not d.Exists(t(i,0)) then d.add tableau(i,0),i 'for j = 1 to ubound(tableau,2) ' t(i,j) = tableau(i,j) 'next else ou = d(t(i,0)) for j = 1 to ubound(tableau,2) t(ou,j) = cdbl(tableau(ou,j)) + cdbl(tableau(i,j)) next t(i,0) = "" end if next redim resultat(d.count-1,2) n = 0 for i = 0 to ubound(t) if t(i,0) <> "" then for j = 0 to ubound(tableau,2) resultat(n,j) t(i,j) : resultat(n,j) t(i,j) : resultat(n,j) = t(i,j) next n = n + 1 end if next ' et je fais maintenant la preuve ====>> for i = 0 to ubound(resultat) msgbox resultat(i,0) & " " & resultat(i,1) & " " & resultat(i,2) next
dim tableau(3,2),d,i,t,j,n, resultat tableau(0,0) = "clef1" tableau(0,1) = "2" tableau(0,2) = "3" tableau(1,0) = "clef2" tableau(1,1) = "2" tableau(1,2) = "-4,35" tableau(2,0) = "clef1" tableau(2,1) = "9" tableau(2,2) = "-5" tableau(3,0) = "clef1" tableau(3,1) = "-3" tableau(3,2) = "8" t = tableau Set d = CreateObject("Scripting.Dictionary") For I = 0 To UBound(tableau) 'a d.Keys : b d.items if not d.Exists(t(i,0)) then d.add tableau(i,0),i else ou = d(t(i,0)) for j = 1 to ubound(tableau,2) t(ou,j) = cdbl(t(ou,j)) + cdbl(t(i,j)) next t(i,0) = "" end if next redim resultat(d.count-1,2) n = 0 for i = 0 to ubound(t) if t(i,0) <> "" then for j = 0 to ubound(tableau,2) resultat(n,j) t(i,j) : resultat(n,j) t(i,j) : resultat(n,j) = t(i,j) next n = n + 1 end if next 'preuve for i = 0 to ubound(resultat) msgbox resultat(i,0) & " " & resultat(i,1) & " " & resultat(i,2) next
Tab4(j,1)=cdbl(Tab4(j,1))+cdbl(Tab3(i,1))
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és 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) dim d,i,t,j,n, Tab4 t = Tab3 Set d = CreateObject("Scripting.Dictionary") For I = 0 To UBound(Tab3) if not d.Exists(t(i,0)) then d.add Tab3(i,0),i t(i,1) = Tab3(i,1) t(i,2) = Tab3(i,2) else ou = d(t(i,0)) t(ou,1) = cdbl(t(ou,1)) + cdbl(t(i,1)) t(ou,2) = cdbl(t(ou,2)) + cdbl(t(i,2)) t(ou,3) = cdbl(t(ou,3)) + cdbl(t(i,3)) t(ou,4) = cdbl(t(ou,4)) + cdbl(t(i,4)) t(ou,5) = cdbl(t(ou,5)) + cdbl(t(i,5)) t(ou,6) = cdbl(t(ou,6)) + cdbl(t(i,6)) t(ou,7) = cdbl(t(ou,7)) + cdbl(t(i,7)) t(ou,8) = cdbl(t(ou,8)) + cdbl(t(i,8)) t(ou,9) = cdbl(t(ou,9)) + cdbl(t(i,9)) t(ou,10) = cdbl(t(ou,10)) + cdbl(t(i,10)) t(ou,11) = cdbl(t(ou,11)) + cdbl(t(i,11)) t(ou,12) = cdbl(t(ou,12)) + cdbl(t(i,12)) t(i,0) = "" end if next redim Tab4(d.count-1,2) n = 0 for i = 0 to ubound(t) if t(i,0) <> "" then for j = 0 to ubound(Tab3,2) Tab4(n,j) t(i,j) : Tab4(n,j) t(i,j) : Tab4(n,j) = t(i,j) next n = n + 1 end if next 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
for j = 0 to ubound(Tab3,2) Tab4(n,j) t(i,j) : Tab4(n,j) t(i,j) : Tab4(n,j) = t(i,j) next