Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1877 connectés 

  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  VBA - appliquer ce code à deux graph au lieu de un

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

VBA - appliquer ce code à deux graph au lieu de un

n°2284628
PsyOps
Posté le 04-07-2016 à 11:53:21  profilanswer
 

Salut,
 
J'ai récupéré un super code mais je cherche à l'appliquer à deux graphiques au lieu d'un seul. Que faut-il changer ?  
 
Ca coince quand je veux modifier Set objChart = wsChart.ChartObjects(1) avec genre Count à la place...
 
Merci [:salutat1ons]
 
 
Option Explicit
 
Public Sub LabelAndColor()
Dim wb As Workbook
Dim wsData As Worksheet, wsChart As Worksheet
Dim objChart As ChartObject
Dim i As Long
 
    Set wb = ActiveWorkbook
    Set wsData = wb.Worksheets("données indiv pour graph" )
    Set wsChart = wb.Worksheets("Graphiques" )
    Set objChart = wsChart.ChartObjects(1)
   
With objChart.Chart.SeriesCollection(1)
        .ApplyDataLabels Type:=xlDataLabelsShowLabel
        For i = 1 To .Points.Count
            With .Points(i)
                .DataLabel.Text = wsData.Cells(i + 2, 1)
                .DataLabel.Font.Size = 9
                .MarkerBackgroundColorIndex = _
                wsData.Cells(i + 2, 1).Interior.ColorIndex
            End With
 
        Next i
    End With
 
    Set objChart = Nothing
    Set wsChart = Nothing: Set wsData = Nothing
 
End Sub

mood
Publicité
Posté le 04-07-2016 à 11:53:21  profilanswer
 

n°2284825
Chelmi18
Posté le 07-07-2016 à 08:48:42  profilanswer
 

Salut,
 
Avant toutes choses, merci de placer ton code entre balises c/c++, cela permettra une meilleure lisibilité et ajoutera les numéros de lignes ...
 
Dans ton code, ajoute et/ou modifie les lignes :

Code :
  1. Option Explicit
  2. Public Sub LabelAndColor()
  3. Dim wb As Workbook
  4. Dim wsData As Worksheet, wsChart As Worksheet
  5. Dim objChart As ChartObject
  6. Dim i As Long
  7.     Set wb = ActiveWorkbook
  8.     Set wsData = wb.Worksheets("données indiv pour graph" )
  9.     Set wsChart = wb.Worksheets("Graphiques" )
  10. -------> For z = 1 to wsChart.ChartObjects.Count
  11.     Set objChart = wsChart.ChartObjects(1) ---- devient -----> Set objChart = wsChart.ChartObjects(z)
  12.  
  13. With objChart.Chart.SeriesCollection(1)
  14.         .ApplyDataLabels Type:=xlDataLabelsShowLabel
  15.         For i = 1 To .Points.Count
  16.             With .Points(i)
  17.                 .DataLabel.Text = wsData.Cells(i + 2, 1)
  18.                 .DataLabel.Font.Size = 9
  19.                 .MarkerBackgroundColorIndex = _
  20.                 wsData.Cells(i + 2, 1).Interior.ColorIndex
  21.             End With
  22.         Next i
  23.     End With
  24.     Set objChart = Nothing
  25. -------> Next z
  26.     Set wsChart = Nothing: Set wsData = Nothing
  27. End Sub


 
En clair, fait une boucle sur tous les objets ChartObjects de ta feuille ...


Message édité par Chelmi18 le 07-07-2016 à 08:51:09

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  VBA - appliquer ce code à deux graph au lieu de un

 

Sujets relatifs
VBA Lien entre 2 cellules feuille différente[VBA] Problème avec tableau
Touche "CTRL" du clavier en VBADecryptage code PHP
[VBA] Travail sur fichier excel en arrière planVBA AIDE
onglet exel caché avec code et accès avec utilisateurAide code C++ faire un rectangle ( noob )
VBA - format histogramme lié à celulles[VB/VBA/VBS] Macro excel d’impression sur plusieurs feuilles.
Plus de sujets relatifs à : VBA - appliquer ce code à deux graph au lieu de un


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR