il y a actuellement sur ce fichier de données 230 000 lignes
Version imprimable
il y a actuellement sur ce fichier de données 230 000 lignes
j'aimerais malgré tout comprendre pourquoi le 2ème code transposé par rapport à ce 1er code formulaR1C1 me renvoi toujours 0 alors que la transposition correspond en tout point tant sur les plages de cellule que sur le critère ?
1er code:
2ème code:Code:
1
2
3 Cells(a, dercolonn + 1).FormulaR1C1 = _ "=SUMIFS(R4C" & dercolonn & ":RC" & dercolonn & ",R4C2:R" & a & "C2,"">=""&TIME(HOUR(R" & a & "C2),MINUTE(R" & a & "C2),SECOND(R" & a & "C2))-TIME(0,0," & choixsec & ")+DATE(YEAR(R" & a & "C2),MONTH(R" & a & "C2),DAY(R" & a & "C2)))"
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14 For a = 5 To derligne criteretime = TimeSerial(Hour(Cells(a, 2)), Minute(Cells(a, 2)), Second(Cells(a, 2))) _ - TimeSerial(0, 0, choixsec) _ + (DateSerial(Year(Cells(a, 2)), Month(Cells(a, 2)), Day(Cells(a, 2)))) Cells(a, dercolonn + 1) = Application.WorksheetFunction.SumIfs _ (Range(Cells(4, dercolonn), Cells(a, dercolonn)), _ Range(Cells(4, 2), Cells(a, 2)), _ ">=" & criteretime) Next a
Bonjour,
il me semble que VBA est capricieux dans ce type de cas
déjà, tu as pas besoin de SumIfs, SumIf suffit amplement
ensuite, quand je suis confronté à ça, je calcule en amont ma date inférieure, et je l'utilise en formatant en date anglaise
essaye ça
Code:
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 Sub glissant() Dim ShtName As String, NameFich As String, chemin As String Dim a As Long, derligne As Long Dim DateInf As Date chemin = Workbooks(ActiveWorkbook.Name).Path NameFich = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 5) ActiveWorkbook.SaveAs Filename:= _ chemin & "\" & NameFich & ".xlsm", FileFormat _ :=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False ShtName = ActiveSheet.Name derligne = Sheets(ShtName).Cells(Rows.Count, 11).End(xlUp).Row dercolonn = Sheets(ShtName).Cells(1, Columns.Count).End(xlToLeft).Column choixsec = InputBox("Combien de secondes glissante (1 à 59) ? ", "Calcul glissant") For a = 5 To derligne DateInf = Cells(a, 2) - CDate("00:00:" & choixsec) Cells(a, dercolonn + 1) = Application.WorksheetFunction.SumIf(Range(Cells(4, 2), Cells(a, 2)), ">=" & Format(DateInf, "mm/dd/yyyy hh:mm:ss"), Range(Cells(4, dercolonn), Cells(a, dercolonn))) Next a MsgBox "Calcul effectué avec succès !", vbOKOnly ActiveWorkbook.Save End Sub
excellent...merci
Avant de crier victoire, regarde si ça fonctionne quand le jour du mois est inférieur à 12 :aie:
remplace tes 25/03/2015 par 04/03/2015 par exemple, et refais le test
tiens nous au courant
non c'est bon ça fonctionne également...merci