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
| 'récupération des données pour graph
Dim PosDonnees As String
z = 1
For i = 1 To CompteurUF2LB
For j = 2 To DernLigne
If ThisWorkbook.Sheets("Feuil5").Range("A" & i).Value = "" Then 'Test valeur vide
Exit For
ElseIf ThisWorkbook.Sheets("Feuil5").Range("A" & i) = xlBook.Sheets("Feuil1").Range("A" & j) Then 'Mise en place de la marge
xlBook.Sheets("F4").Range("A" & z + 1) = ThisWorkbook.Sheets("Feuil5").Range("B" & i)
xlBook.Sheets("F4").Range("B" & z + 1) = "CA"
xlBook.Sheets("F4").Range("B" & z + 2) = "Marge %"
xlBook.Sheets("F4").Range("B" & z + 3) = "Perte %"
x = 11
y = 3
While y <= NbMois + 3 'Récupération des données en fonction des graphiques désirés par l'utilisateur
Lettr = Split(Cells(1, x).Address, "$")(1)
LettrBis = Split(Cells(1, x - 1).Address, "$")(1)
LettrTer = Split(Cells(1, x - 2).Address, "$")(1)
LettrF4 = Split(Cells(1, y).Address, "$")(1)
xlBook.Sheets("F4").Range(LettrF4 & z + 1) = xlBook.Sheets("Feuil1").Range(Lettr & j)
xlBook.Sheets("F4").Range(LettrF4 & z + 2) = xlBook.Sheets("Feuil1").Range(LettrBis & j)
xlBook.Sheets("F4").Range(LettrF4 & z + 3) = xlBook.Sheets("Feuil1").Range(LettrTer & j)
y = y + 1
x = x + 9
Wend
LettrGph = Split(Cells(1, NbMois + 3).Address, "$")(1)
PosDonnees = "B" & z + 1 & ":" & LettrGph & z + 3
xlBook.Sheets("F4").Cells.Copy
ThisWorkbook.Sheets("Feuil7").Paste 'Copie des données du document initial
Set sourcRange = ThisWorkbook.Sheets("Feuil7").Range(PosDonnees)
xlBook.Sheets("Graphs").Activate
Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=sourcRange, PlotBy:= _
xlRows
'ActiveChart.SeriesCollection(1).XValues = "='F4'!R1C3:R1C6"
'ActiveChart.SeriesCollection(2).XValues = "='F4'!R1C3:R1C6"
'ActiveChart.SeriesCollection(3).XValues = "='F4'!R1C3:R1C6"
'ActiveChart.Location Where:=xlLocationAsObject, Name:="Graphs"
With Charts(i)
.HasTitle = True
.ChartTitle.Characters.Text = xlBook.Sheets("F4").Range("A" & z + 1)
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
ActiveChart.SeriesCollection(3).Select
ActiveChart.SeriesCollection(3).AxisGroup = 2
ActiveChart.SeriesCollection(2).Select
ActiveChart.SeriesCollection(2).AxisGroup = 2
Sheets("Graph" & i).Copy
xlBook.Sheets.Add
ActiveSheet.Name = xlBook.Sheets("F4").Range("A" & z + 1)
ActiveSheet.Paste
z = z + 3
End If
Next
Next |
Partager