bonjour le fil,
J'aurai une petite question à vous soumettre , je souhaiterais si possible accelerer le temps de traitement de la macro que j'ai créée (ou plutot enregistrer puis bidouiller en trouvant des astuces à droite et a gauche).
Le principe de la macro est du recuperere un fichier excel pour le remetre en forme et y ajouter des informations pour à la fin réaliser un tableau croisé dynamique.
La macro fonctionne trés bien mais je trouve notamment au moment d'un calcul de moyenne sous la forme que ça rame un peu (plus de 3300 lignes mais qui sur le long terme va croitre)
Vous auriez une petite idée ?
je vous met ci dessous tout le code j'essayerais de mettre une partie du fichier ensuite
merci d'avance
J'aurai une petite question à vous soumettre , je souhaiterais si possible accelerer le temps de traitement de la macro que j'ai créée (ou plutot enregistrer puis bidouiller en trouvant des astuces à droite et a gauche).
Le principe de la macro est du recuperere un fichier excel pour le remetre en forme et y ajouter des informations pour à la fin réaliser un tableau croisé dynamique.
La macro fonctionne trés bien mais je trouve notamment au moment d'un calcul de moyenne sous la forme que ça rame un peu (plus de 3300 lignes mais qui sur le long terme va croitre)
qui en macro se transforme en=SI(ESTERR(MOYENNE.SI(H:H;H2;L:L));"";MOYENNE.SI(H:H;H2;L:L))
pour que le calcul se fasse sur toute les lignes de remplies.Range("m2").Select
Range("m2:m" & Range("B65536").End(xlUp).Row).FormulaR1C1 = "=IF(ISERR(AVERAGEIF(C[-5],RC[-5],C[-1])),"""",AVERAGEIF(C[-5],RC[-5],C[-1]))"
Vous auriez une petite idée ?
je vous met ci dessous tout le code j'essayerais de mettre une partie du fichier ensuite
PHP:
Sub Ellipse2_Clic()
Sheets("Copie extraction").Select
Range("b:c,f:f,h:h,i:m,p:q,s:u").Delete Shift:=xlToLeft
Rows("1:16").Select
Selection.Delete Shift:=xlUp
Range("E1:E50000").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Sheets("Copie extraction").Select
Range("A1:I30000").Select
Selection.Copy
Sheets("Résultat").Select
Range("a1").Select
ActiveSheet.Paste
Columns("G:G").Select
Selection.Find(What:="numéro d'identification:", After:=ActiveCell, LookIn _
:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
Selection.Replace What:="numéro d'identification:", Replacement:="", _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:= _
False, ReplaceFormat:=False
Selection.Replace What:=";", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Columns("B:B").Select
Application.CutCopyMode = False
Selection.TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 4), TrailingMinusNumbers:=True
Columns("B:G").Select
Range("G1").Activate
ActiveWorkbook.Worksheets("Résultat").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Résultat").Sort.SortFields.Add Key:=Range("G2:G3011" _
), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Résultat").Sort.SortFields.Add Key:=Range("B2:B3011" _
), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Résultat").Sort
.SetRange Range("B1:G30110")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Columns("G:G").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("g1").Select
ActiveCell.FormulaR1C1 = "Statut"
Range("G2").Select
Range("g2:g" & Range("B65536").End(xlUp).Row).FormulaR1C1 = "=IF(RC[-1]=2,""vide"",""plein"")"
Range("I1").Select
ActiveCell.FormulaR1C1 = "article"
Range("J1").Select
ActiveCell.FormulaR1C1 = "aire d'appro"
Range("K1").Select
ActiveCell.FormulaR1C1 = "n°boite"
Range("I2").Select
Range("i2:i" & Range("B65536").End(xlUp).Row).FormulaR1C1 = "=VLOOKUP(RC[-1],pkmc!C[-8]:C[-4],3,FALSE)"
Range("J2").Select
Range("j2:j" & Range("B65536").End(xlUp).Row).FormulaR1C1 = "=VLOOKUP(RC[-2],pkmc!C[-9]:C[-5],4,FALSE)"
Range("K2").Select
Range("k2:k" & Range("B65536").End(xlUp).Row).FormulaR1C1 = "=VLOOKUP(RC[-3],pkmc!C[-10]:C[-6],5,FALSE)"
Range("L1").Select
ActiveCell.FormulaR1C1 = "Temps conso"
Range("L2").Select
Range("l2:l" & Range("B65536").End(xlUp).Row).FormulaR1C1 = "=IF(AND(RC[-5]=""vide"",RC[-4]=R[-1]C[-4]),RC[-10]-R[-1]C[-10],"""")"
Range("m1").Select
ActiveCell.FormulaR1C1 = "Moyenne Conso mois en cours"
Range("m2").Select
Range("m2:m" & Range("B65536").End(xlUp).Row).FormulaR1C1 = "=IF(ISERR(AVERAGEIF(C[-5],RC[-5],C[-1])),"""",AVERAGEIF(C[-5],RC[-5],C[-1]))"
Range("N1").Select
ActiveCell.FormulaR1C1 = "Mois "
Range("n2").Select
Range("n2:n" & Range("B65536").End(xlUp).Row).FormulaR1C1 = "=UPPER(TEXT(RC[-12],""mmmm""))"
Range("O1").Select
ActiveCell.FormulaR1C1 = "Moyenne conso mois"
Range("o2").Select
Range("o2:o" & Range("B65536").End(xlUp).Row).FormulaR1C1 = "=IF(ISERR(AVERAGEIFS(C[-3],C[-7],RC[-7],C[-1],RC[-1])<>0),"""",AVERAGEIFS(C[-3],C[-7],RC[-7],C[-1],RC[-1]))"
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Résultat!b1:o999999").CreatePivotTable TableDestination:="", TableName:= _
"Tableau croisé dynamique2"
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
With ActiveSheet.PivotTables("Tableau croisé dynamique2").PivotFields( _
"aire d'appro")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("Tableau croisé dynamique2").PivotFields("article" _
)
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("Tableau croisé dynamique2").PivotFields("n°boite" _
)
.Orientation = xlColumnField
.Position = 1
End With
ActiveSheet.PivotTables("Tableau croisé dynamique2").AddDataField ActiveSheet. _
PivotTables("Tableau croisé dynamique2").PivotFields( _
"Moyenne Conso mois en cours"), "Nombre de Moyenne Conso mois en cours", _
xlCount
With ActiveSheet.PivotTables("Tableau croisé dynamique2").PivotFields( _
"Nombre de Moyenne Conso mois en cours")
.Caption = "Max de Moyenne Conso mois en cours"
.Function = xlMax
End With
End Sub
merci d'avance