IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Mise à jour de l'echelle pour un graphique


Sujet :

Macros et VBA Excel

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    165
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 165
    Points : 62
    Points
    62
    Par défaut Mise à jour de l'echelle pour un graphique
    Bonjour,

    J'ai créer un graphique simple à partir d'un tableau sous excel.

    Je voudrais savoir comment mettre à jour automatiquement les echelles des ordonnées.

    Mon code actuel :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded 16.08.2010 by fd151
    '
    ' Keyboard Shortcut: Ctrl+a
    '
        Charts.Add
        ActiveChart.ChartType = xlLine
        ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1")
        ActiveChart.SeriesCollection.NewSeries
        ActiveChart.SeriesCollection(1).XValues = "=Sheet1!R8C1:R8C14"
        ActiveChart.SeriesCollection(1).Values = "=Sheet1!R3C1:R3C14"
        ActiveChart.SeriesCollection(1).Name = "=""Mois/FTE"""
        ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
        With ActiveChart
            .HasTitle = True
            .ChartTitle.Characters.Text = "Mois/FTE"
            .Axes(xlCategory, xlPrimary).HasTitle = True
            .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "MOIS"
            .Axes(xlValue, xlPrimary).HasTitle = True
            .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "FTE"
        End With
        ActiveChart.HasDataTable = False
    End Sub

  2. #2
    Membre expérimenté Avatar de mayekeul
    Inscrit en
    Août 2005
    Messages
    1 369
    Détails du profil
    Informations forums :
    Inscription : Août 2005
    Messages : 1 369
    Points : 1 665
    Points
    1 665
    Par défaut
    bonjour,

    vu que tu viens juste de le créer, pourquoi mettre à jour??

    mais bon au cas où voici peut-être un code qui t'aidera

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    Sub Macro1prime()
    Dim MyChart As Chart
        Set MyChart = Charts.Add
        With MyChart
            .Name = "monGraphiqueAmoi"
            .ChartType = xlLine
            .SetSourceData Source:=Sheets("Sheet1").Range("A1")
            .SeriesCollection.NewSeries
            .SeriesCollection(1).XValues = "=Sheet1!R8C1:R8C14"
            .SeriesCollection(1).Values = "=Sheet1!R3C1:R3C14"
            .SeriesCollection(1).Name = "=""Mois/FTE"""
            .Location Where:=xlLocationAsObject, Name:="Sheet1"
            .HasTitle = True
            .ChartTitle.Characters.Text = "Mois/FTE"
            .Axes(xlCategory, xlPrimary).HasTitle = True
            .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "MOIS"
            .Axes(xlValue).MinimumScale = 10    'je suppose que c'est cette ligne que tu voulais
            .Axes(xlValue).MaximumScale = 18    'et celle ci aussi...
            .Axes(xlValue, xlPrimary).HasTitle = True
            .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "FTE"
            .HasDataTable = False
        End With
    End Sub

  3. #3
    Membre régulier
    Étudiant
    Inscrit en
    Juin 2010
    Messages
    125
    Détails du profil
    Informations personnelles :
    Âge : 35

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Transports

    Informations forums :
    Inscription : Juin 2010
    Messages : 125
    Points : 105
    Points
    105
    Par défaut
    Salut

    Quel est ton probleme exactement ?

    Une fois, mon echelle se mettait pas a jour automatiquement avec la creation du graph a cause du type de graph choisi.

  4. #4
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    165
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 165
    Points : 62
    Points
    62
    Par défaut Problème graphique
    J'ai essayer de suivre ton code Mayekeul, mais je crois avoir fait une erreur, peux-tu m'aider ?

    Les ordonnées doivent être à jour parce que ce grahique représentent un avancement de projet donc, dans le temps les ordonnées augmenteront, voilà

    Peux-tu me dire pour ce code ?
    Merci


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    Sub Macro1()
     
    'Macro1
    'Macro recorded 16/08/2010 by fd151
    '
    'Keyboard ShortCut: Ctrl + a
     
    Dim MyChart As Chart
    Set MyChart = Charts.Add
    With MyChart 
      .ChartType = xlLine
      .SetSourceDate Source:=Sheets("Sheet3").Range("E15")
      .SeriesCollection.NewSeries
      .SeriesCollection(1).XValue = "=Sheet2!R2C14:R2C30"
    .SeriesCollection(1).Value = "=Sheet2!R43C14:R43C30"
    .SeriesCollection(1).Name = "=""FTE/MOIS"""
    .Location Where:=xlLocationAsObject, Name:="Sheet3"
    .HasTitle = True
    .ChartTitle.Characters.text = _
    "Charge en FTE"
    .Axes(xlCategory, xlPrimary).HasTitle = True
    .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "MOIS"
    .Axes(xlValue).MinimumScale = 0
    .Axes(XlValue).MaximumScale = 10
    .Axes(xlValue, xlPrimary).HasTitle = True
    .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "FTE"
    .HasDataTable = False
    .Shapes("Chart 3").IncrementLeft -9,75
    .Shapes("Chart 3").IncrementTop 1,5
    .PlotArea.Select
    With Selection.Border
            .ColorIndex = 2
            .Weight = xlThin
            .LineStyle = xlContinuous
        End With
        With Selection.Interior
            .ColorIndex = 15
            .PatternColorIndex = 1
            .Pattern = xlSolid
    end with
    MyChart.Axes(xlValue).MajorGridlines.select
    MyChart.PlotArea.select
    With Selection.Border
    .ColorIndex = 2
    .Weight = XlThin
    .LineStyle = xlContinuous
    End with
    With Selection.Interior
    .ColorIndex = 2
    .PatternColorIndex = 1
    .Pattern = XlSolid
    End With
    MyChart.SeriesCollection(1).select
    With Selection.border
    .colorIndex = 3
    .Weight = XlThick
    .LineStyle = xlContinuous
    End With
    With selection
    .MarkerBackgroundColorIndex = xlNone
    .MarkerForegroundColorIndex = xlNone
    .MarkerStyle = xlNone
    .Smooth = False
    .MarkerSize = 3
    .Shadow = False
    End with
    My Chart.Axes(xlValue).select
    End sub

  5. #5
    Membre expérimenté Avatar de mayekeul
    Inscrit en
    Août 2005
    Messages
    1 369
    Détails du profil
    Informations forums :
    Inscription : Août 2005
    Messages : 1 369
    Points : 1 665
    Points
    1 665
    Par défaut
    tu as une erreur à quel endroit du code?

  6. #6
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    165
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 165
    Points : 62
    Points
    62
    Par défaut
    Il sélectionne le "end sub" et marque compil error : expected end with

  7. #7
    Membre expérimenté Avatar de mayekeul
    Inscrit en
    Août 2005
    Messages
    1 369
    Détails du profil
    Informations forums :
    Inscription : Août 2005
    Messages : 1 369
    Points : 1 665
    Points
    1 665
    Par défaut
    effectivement, ce n'est pas fermé

    pour chaque with, tu dois avoir end with

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Sub Macro1prime()
    Dim MyChart As Chart
    Set MyChart = Charts.Add
    With MyChart
        .ChartType = xlLine
        .SetSourceDate Source:=Sheets("Sheet3").Range("E15")
        .SeriesCollection.NewSeries
        .SeriesCollection(1).XValue = "=Sheet2!R2C14:R2C30"
        .SeriesCollection(1).Value = "=Sheet2!R43C14:R43C30"
        .SeriesCollection(1).Name = "=""FTE/MOIS"""
        .Location Where:=xlLocationAsObject, Name:="Sheet3"
        .HasTitle = True
        .ChartTitle.Characters.Text = "Charge en FTE"
        .Axes(xlCategory, xlPrimary).HasTitle = True
        .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "MOIS"
        .Axes(xlValue).MinimumScale = 0
        .Axes(xlValue).MaximumScale = 10
        .Axes(xlValue, xlPrimary).HasTitle = True
        .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "FTE"
        .HasDataTable = False
        .Shapes("Chart 3").IncrementLeft -9, 75
        .Shapes("Chart 3").IncrementTop 1, 5
        .PlotArea.Select
    End With
    With Selection.Border
        .ColorIndex = 2
        .Weight = xlThin
        .LineStyle = xlContinuous
    End With
    With Selection.Interior
        .ColorIndex = 15
        .PatternColorIndex = 1
        .Pattern = xlSolid
    End With
    MyChart.Axes(xlValue).MajorGridlines.Select
    MyChart.PlotArea.Select
    With Selection.Border
        .ColorIndex = 2
        .Weight = xlThin
        .LineStyle = xlContinuous
    End With
    With Selection.Interior
        .ColorIndex = 2
        .PatternColorIndex = 1
        .Pattern = xlSolid
    End With
    MyChart.SeriesCollection(1).Select
    With Selection.Border
        .ColorIndex = 3
        .Weight = xlThick
        .LineStyle = xlContinuous
    End With
    With Selection
        .MarkerBackgroundColorIndex = xlNone
        .MarkerForegroundColorIndex = xlNone
        .MarkerStyle = xlNone
        .Smooth = False
        .MarkerSize = 3
        .Shadow = False
    End With
    MyChart.Axes(xlValue).Select
     
    End Sub

  8. #8
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    165
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 165
    Points : 62
    Points
    62
    Par défaut
    Il créer le graphique, mais il s'arrête en plein milieu en indiquant un message d'erreur : Run-time Error "-21472 21080 (800401a8)" : automation error :

    et il surligne " .hasTitle = False "

  9. #9
    Membre expérimenté Avatar de mayekeul
    Inscrit en
    Août 2005
    Messages
    1 369
    Détails du profil
    Informations forums :
    Inscription : Août 2005
    Messages : 1 369
    Points : 1 665
    Points
    1 665
    Par défaut
    oui je n'avais pas vu

    tu dois déplacer la ligne suivante tout à la fin du code car sinon MyChart perds la référence au graphique

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    .Location Where:=xlLocationAsObject, Name:="Sheet3"

  10. #10
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    165
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 165
    Points : 62
    Points
    62
    Par défaut bug
    Il surligne le bout de code ci-dessous : en indiquant : Unable to get the Characters property of the chartTitle class"

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
        .HasTitle = True
        .ChartTitle.Characters.Text = "Charge en FTE"
    Quel est le problème ?

  11. #11
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    165
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 165
    Points : 62
    Points
    62
    Par défaut Je n'ai toujours pas trouver la solution
    Rebonjour,

    Mon problème n'est toujours pas résolu...
    Merci pour vos réponses

Discussions similaires

  1. Réponses: 2
    Dernier message: 08/06/2009, 22h25
  2. Mise à jour Batterie 1.4 pour MacBook
    Par kOrt3x dans le forum Apple
    Réponses: 0
    Dernier message: 03/03/2009, 00h08
  3. Mise à jour : Mail 3.5 pour 10.5.6
    Par kOrt3x dans le forum Apple
    Réponses: 0
    Dernier message: 24/12/2008, 01h11
  4. mise à jour du driver de la carte graphique
    Par pepper18 dans le forum Composants
    Réponses: 2
    Dernier message: 19/06/2006, 15h58

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo