boucle sur graphiques d'une feuille

juju44

XLDnaute Nouveau
Bonjour à tous,

j'ai souci de programmation :

j'aimerai boucler sur l'ensemble de mes graphiques d'une certaine feuille pour leur appliquer une certaine fonction (mise à l'échelle)

Code:
Sheets(3).ChartObjects(1).Activate
Echelle "Graphique 1", "abs1", "ord1"

Sheets(3).ChartObjects(2).Activate
Echelle "Graphique 2", "abs2", "ord2"
        
Sheets(3).ChartObjects(3).Activate
Echelle "Graphique 3", "abs3", "ord3"


Voila par quoi je voudrai remplacer ces lignes :


Code:
Dim z As Integer
Dim nbgraph As Integer
        
nbgraph = Sheets(3).ChartObjects.Count

For z = nbgraph To 1 Step -1
       Sheets(3).Activate
       Echelle "Graphique " & z, "abs" & z, "ord" & z
Next z

Mais la syntaxe ne semble pas correcte.

Merci d'avance
 

juju44

XLDnaute Nouveau
Re : boucle sur graphiques d'une feuille

Merci pour ta réponse :

Voila la procédure échelle :

Code:
Sub Echelle(Graph, abscisses, ordonnees)
    With ActiveSheet.ChartObjects(Graph).Chart.Axes(xlValue)
    Min = Application.Min(Range(ordonnees))
    Max = Application.Max(Range(ordonnees))
    
    If Min < 0 Then
    Min = Application.RoundUp(Min, 2)
    Else
    Min = Application.RoundDown(Min, 2)
    End If
    
    Max = Application.RoundUp(Max, 2)
    
    .CrossesAt = Min
    .MinimumScale = Min
    .MaximumScale = Max
    .MajorUnit = (Max - Min) / 4
    End With
    
    With ActiveSheet.ChartObjects(Graph).Chart.Axes(xlCategory)
    Min = Application.Min(Range(abscisses))
    Max = Application.Max(Range(abscisses))
    
    If Min < 0 Then
    Min = Application.RoundUp(Min, 2)
    Else
    Min = Application.RoundDown(Min, 2)
    End If
    
    Max = Application.RoundUp(Max, 2)

    .CrossesAt = Min
    .MinimumScale = Min
    .MaximumScale = Max
    .MajorUnit = (Max - Min) / 4
    End With
End Sub
 

kjin

XLDnaute Barbatruc
Re : boucle sur graphiques d'une feuille

Bonsoir,
J'ai qq peu remanié la macro mais rien de fondamental, donc si tu es sûr des plages nommées et du nom des graphiques je ne vois pas où est de pb
Joins un extrait du fichier éventuellement
Code:
Sub MiseEchelle()
Dim z As Byte, nbgraph As Byte 'à moins qu'il y en ait plus de 255 !
nbgraph = Sheets(3).ChartObjects.Count
For z = 1 To nbgraph 'pourquoi boucler à l'envers ?!
    Echelle Sheets(3), "Graphique " & z, "abs" & z, "ord" & z
Next z
End Sub

Sub Echelle(ws As Worksheet, Graph$, abscisses$, ordonnees$)
Dim Min#, Max#
With ws.ChartObjects(Graph).Chart

    Min = Application.Min(Range(ordonnees))
    Max = Application.Max(Range(ordonnees))
    If Min < 0 Then
        Min = Application.RoundUp(Min, 2)
    Else
        Min = Application.RoundDown(Min, 2)
    End If
    Max = Application.RoundUp(Max, 2)
    With .Axes(xlValue)
        .CrossesAt = Min
        .MinimumScale = Min
        .MaximumScale = Max
        .MajorUnit = (Max - Min) / 4
    End With
    
    Min = Application.Min(Range(abscisses))
    Max = Application.Max(Range(abscisses))
    If Min < 0 Then
        Min = Application.RoundUp(Min, 2)
    Else
        Min = Application.RoundDown(Min, 2)
    End If
    Max = Application.RoundUp(Max, 2)
    With .Axes(xlCategory)
        .CrossesAt = Min
        .MinimumScale = Min
        .MaximumScale = Max
        .MajorUnit = (Max - Min) / 4
    End With
    
End With
End Sub
A+
kjin
 

Discussions similaires

Réponses
11
Affichages
927