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
| Sub total()
Dim derligne As Integer, ntache As Integer, i As Integer, j As Integer, k As Integer
Dim trouve As Range
Dim plsemainetot As Range
Dim objectif As Variant
Dim plsemaines As Range
Dim coldroite As Integer
Dim lsemaine As Range
Dim Nbcolonnes As Integer, Min As Integer, Max As Integer, SMax As Integer, SMin As Integer
Dim col As Integer
derligne = Range("A65536").End(xlUp).Row
ntache = 0
SMax = 0
SMin = 52
For i = derligne To 1 Step -1
If Cells(i, 1).Interior.ColorIndex = 37 Then
objectif = objectif + Cells(i, 1).Value
End If
If Cells(i, 1).Value = "Semaine" Then
coldroite = Cells(i, 100).End(xlToLeft).Column
Set plsemaines = Range(Cells(i, 2), Cells(i, coldroite))
Min = WorksheetFunction.Min(plsemaines)
Max = WorksheetFunction.Max(plsemaines)
If Min < SMin Then SMin = Min
If Max > SMax Then SMax = Max
End If
Next i
Nbcolonnes = SMax - SMin + 1
With Cells(derligne + 2, 1)
.Value = objectif
.Interior.ColorIndex = 37
End With
With Range(Cells(derligne + 2, 2), Cells(derligne + 2, Nbcolonnes + 3))
.Merge
.Value = "TOTAL"
.Interior.ColorIndex = 36
End With
Cells(derligne + 3, 1).Value = "Semaine"
Cells(derligne + 4, 1).Value = "Réalisé"
Cells(derligne + 5, 1).Value = "Cumul Réalisé"
Cells(derligne + 6, 1).Value = "RAF"
Cells(derligne + 7, 1).Value = "% Réalisé"
Cells(derligne + 8, 1).Value = "% Chiffrage"
Cells(derligne + 4, 2).Value = 0
Cells(derligne + 5, 2).Value = 0
Cells(derligne + 6, 2).Value = objectif
Cells(derligne + 7, 2).Value = 0
Cells(derligne + 8, 2).Value = 0
For j = 0 To Nbcolonnes - 1
Cells(derligne + 3, j + 3).Value = SMin + j
Next j
Set plsemainetot = Range(Cells(derligne + 3, 2), Cells(derligne + 3, Nbcolonnes + 3))
For i = derligne To 1 Step -1
If Cells(i, 1).Value = "Semaine" Then
For k = 3 To Cells(i, 100).End(xlToLeft).Column
Set trouve = plsemainetot.Find(Cells(i, k).Value, plsemainetot.Cells(1), xlValues, xlWhole, xlByRows, xlNext)If trouve Is Nothing Then
GoTo suite
Else
col = trouve.Column
End If
Cells(derligne + 4, col).Value = Cells(i + 1, k).Value + Cells(derligne + 4, col).Value
suite:
Next k
End If
Next i
With Range(Cells(derligne + 2, 1), Cells(derligne + 8, Nbcolonnes + 3))
.Borders.LineStyle = xlContinuous
.Borders(xlEdgeBottom).Weight = xlMedium
.Borders(xlEdgeLeft).Weight = xlMedium
.Borders(xlEdgeRight).Weight = xlMedium
.Borders(xlEdgeTop).Weight = xlMedium
.Borders(xlInsideHorizontal).Weight = xlThin
.Borders(xlInsideVertical).Weight = xlThin
End With
End Sub |
Partager