Se connecter avec
S'enregistrer | Connectez-vous

macro Excel VBA : création graphiques/graphes automatique

Dernière réponse : dans Programmation

bjr, j'ai 1 macro qui génère automatiquement des graphes/graphiques, ça marche.
Mais, 1 fois le graphe créé, sur une boucle, je n'arrive pas à reprndre le graphe pour modifier le style de la courbe, quelqu'un connait-il la solution ?
Merci.

  1. Sub ifcourbes()
  2.  
  3. '
  4. ' ifcourbes Macro
  5. ' Macro enregistrée le 12/02/2007 par ericE
  6. '
  7. Sheets("tableau").Select
  8. Range("AN6").Select
  9.  
  10. 'maxlig = Range("B65535").End(xlUp).Row
  11. maxlign = 6
  12.  
  13. For i = 2 To maxlign
  14. 'Sheets("tableau").Select
  15.  
  16. recup = Cells(i, 35)
  17.  
  18. If Cells(i, 31) < 500 Then
  19. 'Sheets("tableau").Select
  20.  
  21. Select Case recup
  22. Case ""
  23. Cells(i, 42) = "tropfort"
  24. Case Is > 0.7
  25. Cells(i, 42) = "vu1"
  26. Case 0.6 To 0.7
  27. Cells(i, 42) = "vu11"
  28. Case Is < 0.6
  29. Cells(i, 42) = "vu121"
  30. End Select
  31.  
  32. Else
  33.  
  34. Select Case recup
  35. Case ""
  36. Cells(i, 43) = "nonvu"
  37.  
  38. Case Is > 0.7
  39. appelfonction = casfort(i)
  40.  
  41. Case 0.6 To 0.7
  42. Cells(i, 43) = "vu11"
  43. Case Is < 0.6
  44. Cells(i, 43) = "vu121"
  45. End Select
  46. End If
  47.  
  48. Next
  49.  
  50. Range("AN6").Select
  51.  
  52.  
  53. End Sub
  54.  
  55. Function casfort(j) As Integer
  56. 'Public ChartList As Integer
  57. Dim sha As ChartObject
  58.  
  59. maxlign = 5
  60. m = 1
  61.  
  62. For j = 2 To maxlign
  63.  
  64. 'k = j + 22
  65. Sheets("fort").Select
  66. Cells(j * 22, 1).Select
  67. 'Cells(j * 25, 1).Select
  68. 'Cells(j * 22, 1).Select
  69. Charts.Add
  70.  
  71.  
  72. 'ChartList = ActiveSheet.ChartObjects.Count
  73. 'm = ChartList * 15
  74.  
  75. 'ActiveChart.ChartType = xlLine
  76. 'ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:= _
  77. "Courbes à deux axes"
  78. ActiveChart.SetSourceData Source:=Sheets("tableau").Range("A1:AM123"), _
  79. PlotBy:=xlRows
  80.  
  81. ActiveChart.SeriesCollection.NewSeries
  82. 'Sheets("tableau").Select
  83. ActiveChart.SeriesCollection(1).XValues = _
  84. "=(tableau!R1C3,tableau!R1C4,tableau!R1C6,tableau!R1C8,tableau!R1C10)"
  85.  
  86. 'k = j + 1
  87.  
  88. 'lignier2 = "=(tableau!R" & j & "C3," & "tableau!R" & j & "C4," _
  89. & "tableau!R" & j & "C6," & "tableau!R" & j & "C8," & "tableau!R" & j & "C10)"
  90.  
  91. lignier1 = "=(tableau!R" & j & "C3," & "tableau!R" & j & "C4," _
  92. & "tableau!R" & j & "C6," & "tableau!R" & j & "C8," & "tableau!R" & j & "C10)"
  93.  
  94. lignier2 = "=(tableau!R" & j & "C5," & "tableau!R" & j & "C7," _
  95. & "tableau!R" & j & "C9," & "tableau!R" & j & "C11," & "tableau!R" & j & "C13)"
  96.  
  97. 'title2 = "=(tableau!R" & j & "C1," & "tableau!R" & j & "C2"
  98. valide1 = Sheets("tableau").Cells(j, 1)
  99. validier = Sheets("tableau").Cells(j, 2)
  100. valide = valide1 & " " & validier
  101.  
  102. ActiveChart.SeriesCollection(1).Values = lignier1
  103. ActiveChart.SeriesCollection(1).Name = "=""Em"""
  104.  
  105. 'ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:= _
  106. "Courbes à deux axes"
  107. ActiveChart.SeriesCollection(2).Values = lignier2
  108. ActiveChart.SeriesCollection(2).Name = "=""Energie"""
  109.  
  110. ActiveChart.Location Where:=xlLocationAsObject, Name:="TBpforte"
  111.  
  112. ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:= _
  113. "Courbes à deux axes"
  114.  
  115. Sheets("TBpforte").Select
  116. ActiveChart.PlotArea.Select
  117. 'ActiveChart.ChartType = xlLine
  118.  
  119. ActiveWindow.Visible = False
  120.  
  121. With ActiveChart
  122. .HasTitle = True
  123. .ChartTitle.Characters.Text = valide
  124. .Axes(xlCategory, xlPrimary).HasTitle = True
  125. .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "mois"
  126. .Axes(xlValue, xlPrimary).HasTitle = True
  127. .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "KW"
  128. .Axes(xlCategory, xlSecondary).HasTitle = False
  129. .Axes(xlValue, xlSecondary).HasTitle = False
  130. End With
  131.  
  132. With ActiveChart.Axes(xlCategory)
  133. .HasMajorGridlines = False
  134. .HasMinorGridlines = False
  135. End With
  136. With ActiveChart.Axes(xlValue)
  137. .HasMajorGridlines = True
  138. .HasMinorGridlines = False
  139. End With
  140.  
  141. ActiveChart.HasDataTable = False
  142. ActiveChart.Axes(xlCategory).Select
  143. ActiveChart.Axes(xlValue).Select
  144.  
  145. ActiveChart.PlotArea.Select
  146.  
  147. ActiveChart.SeriesCollection(2).Select
  148. With Selection.Border
  149. .Weight = xlThin
  150. .LineStyle = xlAutomatic
  151. End With
  152. With Selection
  153. .MarkerBackgroundColorIndex = xlAutomatic
  154. .MarkerForegroundColorIndex = 46
  155. .MarkerStyle = xlDiamond
  156. .Smooth = False
  157. .MarkerSize = 5
  158. .Shadow = False
  159. End With
  160. With Selection.Border
  161. .ColorIndex = 46
  162. .Weight = xlThin
  163. .LineStyle = xlContinuous
  164. End With
  165. With Selection
  166. .MarkerBackgroundColorIndex = 46
  167. .MarkerForegroundColorIndex = 46
  168. .MarkerStyle = xlDiamond
  169. .Smooth = False
  170. .MarkerSize = 5
  171. .Shadow = False
  172. End With
  173.  
  174.  
  175. Sheets("tableau").Select
  176.  
  177. Next
  178.  
  179. Sheets("fort").Select
  180. Range("A1").Select
  181. 'Rows("1:15").Select
  182. Rows("1:30").Select
  183. Selection.Delete Shift:=xlUp
  184. 'Range("A1").Select
  185. Columns("A:B").EntireColumn.Delete
  186. 'Columns("A:C").EntireColumn.Delete
  187.  
  188.  
  189. End Function


msg : "La méthode Select de la classe Axis a échoué."

ActiveChart.Axes(xlCategory).Select à déboder

pb : "ActiveChart.PlotArea.Select" ne marche pas sur une boucle
pour 1 seule courbe, c'est OK, sinon, non sur une boucle !

quelqu'un sait-il ?

Merci
Techneric
Lassé par la pub ? Créez un compte
Lassé par la pub ? Créez un compte