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
| Option Explicit
Sub Graphe()
Dim c As Byte
EffaceGraphe "Feuil2"
If Worksheets("Feuil1").CheckBox1.Value = True Then
TraceGraphe "Feuil2", 7
c = c + 1
End If
If Worksheets("Feuil1").CheckBox2.Value = True Then
TraceGraphe "Feuil2", 8
c = c + 1
End If
If Worksheets("Feuil1").CheckBox3.Value = True Then
TraceGraphe "Feuil2", 5
c = c + 1
End If
If c > 0 Then PlaceGraphe "Feuil2", c
End Sub
'Efface les graphiques existants
Private Sub EffaceGraphe(ByVal Sht As String)
Dim ChObj As ChartObject
For Each ChObj In Worksheets(Sht).ChartObjects
ChObj.Delete
Next ChObj
End Sub
'Trace les graphiques
Private Sub TraceGraphe(ByVal Sht As String, ByVal Col As Integer)
With Worksheets(Sht).ChartObjects.Add(0, 0, 300, 180).Chart
.ChartType = xlLine
With .SeriesCollection.NewSeries
.Name = "='" & Sht & "'!" & Worksheets(Sht).Cells(1, Col).Address
.Values = "='" & Sht & "'!" & Worksheets(Sht).Cells(2, Col).Resize(21, 1).Address
End With
End With
End Sub
'Place les graphiques
Private Sub PlaceGraphe(ByVal Sht As String, ByVal Ind As Byte)
Dim i As Byte, j As Byte, k As Byte
With Worksheets(Sht)
For k = 1 To Ind
Select Case Ind
Case 1
.ChartObjects(k).Left = .Cells(1, 10).Left
.ChartObjects(k).Top = .Range("A23").Top
Case 2
.ChartObjects(k).Left = .Cells(1, 7 * k).Left
.ChartObjects(k).Top = .Range("A22").Top
Case 3
i = IIf(k = 3, 14, 27)
j = IIf(k = 3, 9, 6 * k)
.ChartObjects(k).Left = .Cells(1, j).Left
.ChartObjects(k).Top = .Cells(i, 1).Top
End Select
Next k
End With
End Sub |