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
| Option Explicit
Const Feuille As String = "test" 'Nom de la feuille, à adapter
Sub Histogramme()
Dim FinH As Integer, Dim1 As Integer, i As Integer, j As Integer, k As Integer
Dim TabCumul() As Double
Dim Cht As ChartObject
Dim TabD() As String
Dim Flag As Boolean
Dim DebutV As Long
Dim c As Range
Application.ScreenUpdating = False
With ThisWorkbook.Worksheets(Feuille)
If .ChartObjects.Count > 0 Then .ChartObjects.Delete
Set c = .Range("A:A").Find("test", LookIn:=xlValues, lookat:=xlPart)
If Not c Is Nothing Then
DebutV = c.Row
Set c = Nothing
FinH = .Cells(DebutV, .Columns.Count).End(xlToLeft).Column
Dim1 = 1 + (FinH - 14) / 5
ReDim TabD(0 To Dim1)
ReDim TabCumul(0 To Dim1)
For i = 14 To FinH Step 5
If Not Flag And .Cells(DebutV - 9, 11).Value < .Cells(DebutV, i).Value Then
TabD(j) = "etalon"
TabCumul(j) = .Cells(DebutV - 9, 11).Value
Flag = True
j = j + 1
k = j
End If
TabD(j) = .Cells(2, i).Value
TabCumul(j) = .Cells(DebutV, i).Value
j = j + 1
Next i
If Not Flag Then
TabD(j) = "etalon"
TabCumul(j) = .Cells(DebutV - 9, 11).Value
k = j + 1
End If
Set Cht = .ChartObjects.Add(.Range("A50").Left + 5, .Range("A50").Top + 5, 550, 310)
With Cht.Chart
.Legend.Delete
.ChartArea.Format.Line.Visible = False
.Axes(xlCategory).TickLabels.Orientation = 30
With .SeriesCollection.NewSeries
.XValues = TabD
.Values = TabCumul
.Border.ColorIndex = 5
With .Format
With .Fill.ForeColor
.ObjectThemeColor = msoThemeColorText1
.Brightness = 0.349999994
End With
.Line.Visible = msoFalse
End With
.Points(k).Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
End With
End With
Set Cht = Nothing
End If
End With
End Sub |