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
| Private Sub CommandButton2_Click()
'gère le bouton tracer
Dim MonGraphe As Chart, MaSerie As Series, compteur As Long, nomfichier As String
Dim PlageX As Range, PlageY As Range, MaFeuille As Worksheet, PlageDonnees As Range
Dim ligne As Integer, ncol As Long, Axe As Axis
'récupération nom du fichier excel actif
nomfichier = ActiveWorkbook.Name
'permet de faire reference a la feuille sans avoir a tout taper
Set MaFeuille = Workbooks(nomfichier).Worksheets("Feuil1")
'detection nombre lignes & colonnes
ncol = MaFeuille.Cells(13, "F").End(xlToRight).Column
ligne = MaFeuille.Cells(Rows.Count, "F").End(xlUp).Row
Set PlageDonnees = MaFeuille.Range("F13", MaFeuille.Cells(ligne, ncol))
'Application.ScreenUpdating = False
For compteur = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(compteur) Then
If MonGraphe Is Nothing Then
Set MonGraphe = MaFeuille.ChartObjects.Add(100, 100, 500, 350).Chart
MonGraphe.ChartArea.Clear
MonGraphe.ChartType = xlXYScatterSmoothNoMarkers
End If
Set PlageX = PlageDonnees.Columns(Me.ComboBox3.ListIndex + 1)
Set PlageY = PlageDonnees.Columns(compteur + 1)
Set MaSerie = MonGraphe.SeriesCollection.NewSeries
With MaSerie
.Values = PlageY
.XValues = PlageX
End With
End If
Next compteur
If Not MonGraphe Is Nothing Then
If Len(Me.ComboBox1.Text) > 0 Then
MonGraphe.HasTitle = True
MonGraphe.ChartTitle.Characters.Text = Workbooks(nomfichier).Worksheets("Feuil2").Range("g6")
End If
MonGraphe.HasLegend = Me.CheckBox3.Value
If MonGraphe.HasLegend And Me.OptionButton1 Then
MonGraphe.Legend.Position = xlLegendPositionLeft
End If
End If
For Each MaSerie In MonGraphe.SeriesCollection
MaSerie.FormulaR1C1Local = Replace(MaSerie.FormulaR1C1Local, "L13C", "L14C")
'If InStr(1, MaSerie.Name, "Pression reacteur", vbTextCompare) > 0 Then
'MaSerie.AxisGroup = xlSecondary
' End If
Next MaSerie
With MonGraphe
'action sur l'axe des X
Set Axe = .Axes(xlCategory, xlPrimary)
With Axe
.HasTitle = True
.AxisTitle.Text = ComboBox3
End With
'action sur l'axe des ordonnées à gauche
Set Axe = .Axes(xlValue, xlPrimary)
With Axe
.HasTitle = True
.AxisTitle.Text = ComboBox6
End With
'action sur l'axe des ordonnées de droite
' Set Axe = .Axes(xlValue, xlSecondary)
'With Axe
' .HasTitle = True
' .AxisTitle.Text = Workbooks(nomfichier).Worksheets("Feuil2").Range("C6").Value
End With
End Sub |
Partager