| 12
 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
 
 | Sub Traitement_masse_ENEDIS()
   Dim i As Long, j As Long, k As Long
   Dim nb_rows As Integer, nb_col As Long
   Dim nb_sites As Integer
   Dim Liste_RAE As Range
   Dim Liste_RAE_ENEDIS As Range
   Dim dDate As Date
   '--- recopie feuille active avant traitement avec ENEDIS comme nom
   ActiveSheet.Copy after:=ActiveSheet
   ActiveSheet.Name = "ENEDIS"
   '---
   nb_rows = ActiveSheet.UsedRange.Rows.Count
   For k = 1 To 10
      For i = 1 To nb_rows * 1.5
         If Cells(i, 5) = "DQ" Then
            Rows(i).Delete             '--- supprime ligne contenant DQ en colonne 5
            i = i - 1                  '--- remonter d'une ligne (pour supprimer ligne suivante avec DQ)
            Debug.Print "ligne " & i & " supprimée"
         End If
      Next i
   Next k
   '--- Separation des groupes
   Cells(1, 1).Activate
   nb_rows = ActiveSheet.UsedRange.Rows.Count
   For i = 2 To nb_rows             '--- commence en ligne 2, 1er groupe
      If Cells(i, 1) <> Cells(1 + i, 1) And Cells(i, 1) <> 0 Then
         ActiveSheet.Rows(i + 1).Insert
      End If
   Next i
   '--- Creation Tableau
   nb_rows = ActiveSheet.UsedRange.Rows.Count
   nb_col = ActiveSheet.UsedRange.Columns.Count
   Range(Cells(2, 4), Cells(nb_rows, 4)).Copy _
      Destination:=Range(Cells(2, 90), Cells(nb_rows, 90))  '--- copie colonne 4
   '---
   For j = 2 To nb_rows             '--- commence à la ligne 2
      For i = 7 To nb_col Step 3    '--- commence en colonne 7 et avance par pas de 3: 7,10,13, ...
         dDate = Cells(j, i + 1)                            '--- en colonne 8,11, 14,...
         'Debug.Print dDate, Month(dDate), Year(dDate)
         If Year(dDate) = 2018 Then                         '--- uniquement année 2018
            k = 103 - Month(dDate)                          '--- colonne du mois
            If Cells(j, 6) = "VA" Or Cells(j, 6) = "W" Then
               Cells(j, k) = WorksheetFunction.Max(Cells(j, k), Cells(j, i))  '--- max
            Else
               Cells(j, k) = Cells(j, k) + Cells(j, i)                        '--- cumul
            End If
         End If
      Next i
   Next j
   '--- titre tableau
   Range("CM1") = "Decembre"
   Range("CN1") = "Novembre"
   Range("CO1") = "Octobre"
   Range("CP1") = "Septembre"
   Range("CQ1") = "Aout"
   Range("CR1") = "Juillet"
   Range("CS1") = "Juin"
   Range("CT1") = "Mai"
   Range("CU1") = "Avril"
   Range("CV1") = "Mars"
   Range("CW1") = "Fevrier"
   Range("CX1") = "Janvier"   '--- colonne 102
   Range("CY1") = "Total"     '--- colonne 103
   '---
   For i = 2 To nb_rows
      '--- colonne 103: "Total"
      If Cells(i, 6) = "Wh" Then
         Cells(i, 103) = Application.WorksheetFunction.Sum(Range(Cells(i, 91), Cells(i, 102))) / 1000
         Cells(i, 104) = "k" & (Cells(i, 6))
      ElseIf Cells(i, 6) = "W" Or Cells(i, 6) = "VA" Then
         Cells(i, 103) = Application.WorksheetFunction.Max(Range(Cells(i, 91), Cells(i, 102))) / 1000
         Cells(i, 104) = "k" & (Cells(i, 6))
      ElseIf Cells(i, 6) <> "" Then
         Cells(i, 103) = Application.WorksheetFunction.Sum(Range(Cells(i, 91), Cells(i, 102)))
         Cells(i, 104) = (Cells(i, 6))
      End If
   Next
   Stop           '--- instruction à supprimer après vérification
   '--- DEL base ------- pourquoi à la fin et pas avant de faire les calculs ?
   For k = 2 To nb_rows
      If Cells(k, 3) = "DI000001" _
         And (Cells(k + 1, 3) = "FC000010" Or Cells(k + 1, 3) = "FC000023") Then
         '--- attention aux parenthèses
         '--- If X and (Y or Z)  n'est pas la même chose que  If X and Y or Z
         '--- exemple If True and True or False ci dessous
         If Cells(k - 1, 103) <= Cells(k, 103) Then      '--- 103 = colonne CY
            '--- pas d'erreur ?
            Cells(k - 1, 3).EntireRow.Delete      '--- supprime ligne au-dessus de "DI000001"
         Else
            '--- pas d'erreur ?
            Cells(k, 3).EntireRow.Delete  '--- supprime ligne "DI000001"
            Cells(k, 3).EntireRow.Delete  '--- supprime ligne "FC000010" ou "FC000023"
         End If
      End If
   Next k
End Sub |