FORUM Tom's Hardware » Programmation » VB / VBA / VBS » macro Excel VBA : création graphiques/graphes automatique
 

macro Excel VBA : création graphiques/graphes automatique

Thor941, rastadd Le Bistrot : killerjeff Réseaux : agoriane Programmation : Pennes Les news : vos réactions : paul ochon et 333 utilisateurs inconnus
Ajouter une réponse



 Mot :   Pseudo :  
 
Bas de page
Auteur
 Sujet : macro Excel VBA : création graphiques/graphes automatique
 
Plus d'informations

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.

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

zeb
Profil : Modérateur libre
Plus d'informations

Tu peux lire la moitié de mes commentaires sur Excel VBA sur ce forum :
JE HAIS LES "SELECT/SELECTION".

La soluce dans ce topic http://www.presence-pc.com/forum/p [...] 2941-1.htm

Plus d'informations

Merci, je vais regarder ! A plus !


Aller à :
Ajouter une réponse
  FORUM Tom's Hardware » Programmation » VB / VBA / VBS » macro Excel VBA : création graphiques/graphes automatique
 

Annonces Google
Publicité