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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
| Public Val As Double
Sub bouton1()
Val = 1
Call SelectRap
End Sub
Sub bouton2()
Val = 2
Call SelectRap
End Sub
Sub SelectRap()
Application.DisplayAlerts = False
Dim NbL As Integer
Dim i, j, k, y, z, p, q As Integer
Dim nombre, BdDcol, nomSite As Integer
Dim V As String
Dim f As Integer
Dim Graph As ChartObject
Dim chGraph As Chart
Dim rPlageAcceuil As Range
Dim rPlageSource As Range
Dim plage1, plage2, plage3
Set A = ThisWorkbook.Sheets("Accueil")
With A
If Val = O Then
MsgBox ("Selectionnez un type de rapport")
End If
V = A.OLEObjects("combobox" & Val).Object.Value
End With
Application.ScreenUpdating = False
'------
With ThisWorkbook
Set S = Sheets("Source")
Set B = Sheets("BdD")
Set R = Sheets("Rapport")
Set M = Sheets("Mémoire")
R.Range("J" & 4).Value = V 'titre
Select Case Val
Case 1
BdDcol = 2
Case 2
BdDcol = 3
End Select
nombre = 0 ' compteur
For i = 2 To B.[A65000].End(xlUp).Row
If V = B.Cells(i, BdDcol).Value Then
nombre = nombre + 1 ' Nombre de tableaux et graphiques
S.Select
S.Rows("1:32").Select
Selection.Copy
R.Select
R.Rows(80 + (nombre - 1) * 32).Select
ActiveSheet.Paste
M.Select
Application.CutCopyMode = False
nomSite = 81 + (nombre - 1) * 32 ' pour cellule ou se colle le nom du site
R.Range("D" & 81 + (nombre - 1) * 32).Value = B.Range("B" & i).Value ' liste des centrales
'-------- insertion graphiques
R.Select
With Sheets("Rapport")
' Plage devant accueuillir le graphique
Set rPlageAcceuil = R.Cells(nomSite + 12, 4).Offset(0, 0)
Set chGraph = .ChartObjects.Add(rPlageAcceuil.Left, rPlageAcceuil.Top, 625, 175).Chart ' rPlageAcceuil.Width, rPlageAcceuil.Height
End With
'----récuparation des données graphiques
With Worksheets("Graphiques") ' plage des données graphiques à faire correspondre à la génération
Set G = ThisWorkbook.Sheets("Graphiques")
For p = 2 To G.[A65000].End(xlUp).Row
If G.Range("A" & p).Value = R.Range("D" & 81 + (nombre - 1) * 32).Value Then
Set plage = Sheets("Graphiques").Range(.Cells(1, 9), .Cells(1, 39))
Set plage1 = Sheets("Graphiques").Range(.Cells(p, 9), .Cells(p, 39))
Set plage2 = Sheets("Graphiques").Range(.Cells(p + 1, 9), .Cells(p + 1, 39))
Set plage3 = Sheets("Graphiques").Range(.Cells(p + 2, 9), .Cells(p + 2, 39))
End If
Next p
End With
R.Select
With chGraph
.SeriesCollection.NewSeries
.FullSeriesCollection(1).Name = Sheets("Graphiques").Cells(3, 8).Text ' nom de la serie (production)
.FullSeriesCollection(1).XValues = plage
.FullSeriesCollection(1).Values = plage1
.FullSeriesCollection(1).ChartType = xlColumnClustered
.SeriesCollection.NewSeries
.FullSeriesCollection(2).Name = Sheets("Graphiques").Cells(4, 8).Text ' nom de la serie (production th)
.FullSeriesCollection(2).XValues = plage
.FullSeriesCollection(2).Values = plage2
.FullSeriesCollection(2).ChartType = xlXYScatterSmoothNoMarkers
.SeriesCollection.NewSeries
.FullSeriesCollection(3).Name = Sheets("Graphiques").Cells(5, 8).Text ' nom de la serie (bp)
.FullSeriesCollection(3).XValues = plage
.FullSeriesCollection(3).Values = plage3
.FullSeriesCollection(3).ChartType = xlLine
.Axes(xlCategory, xlSecondary).Delete
.HasTitle = False
' Intitulé
'.ChartTitle.Characters.Text = Sheets("Graphiques").Cells(p, 1).Text
' Légende en position haute
' .Legend.Position = xlLegendPositionTop
End With
End If 'premiere condition
Next i
MsgBox (nombre & " Tableau(x) généré(s) pour " & V)
End With
R.Select
ActiveSheet.PageSetup.PrintArea = "$B$2:$S$" & ((80 + (nombre) * 32)) ' permet de définir la zone d'imp, les sauts de page seront visibles dans cette zone
'-------------------------------
Application.Run ("sautdepage")
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub |
Partager