Paramétrer des barres d'erreur par VBA

Bonjour,

J'essaie de modifier les barres d'erreur d'un graphe par vba. voici mon code:

ChartObjects("Graph3").Activate
        With ActiveChart
            .SeriesCollection(1).XValues = Sheets("U").Range("F" & PL1 & ":F" & PLn)
            .SeriesCollection(1).Values = Sheets("U").Range("H" & PL1 & ":H" & PLn)
            .SeriesCollection(2).XValues = Sheets("U").Range("F" & PL1 & ":F" & PLn)
            .SeriesCollection(2).Values = Sheets("U").Range("AP" & PL1 & ":AP" & PLn)
            .FullSeriesCollection(1).ErrorBars.Select
            .FullSeriesCollection(1).ErrorBar Direction:=xlY, Include:= _
                xlBoth, Type:=xlCustom, Amount:=(ActiveSheet.Range("G" & PL1 & ":G" & PLn).Value)
        End With

Tout se passe correctement jusqu'à la dernière ligne du With, message renvoyé: incompatibilité de type.

J'ai essayé aussi: Amount:=ActiveSheet.Range("G" & PL1 & ":G" & PLn) mais c'est pareil.

Quelqu'un saurait où est l'erreur ?

Merci d'avance.

Bonjour,

le sujet ne semble intéresser personne.... Dommage.

Bonjour,

Ne penses tu pas qu'il manque quelque chose à ta demande ?

Cdlt.

s'il vous plaît ???

bonjour, voila ce qui manque.......

fred

Bonjour à tous,

Donc voici le fichier.

La macro copie bien le tableau, le graphique se met à jour mais pas les barres d'erreur.

Pourriez-vous m'aider à résoudre ce problème ?

Merci beaucoup

pascal

Bonjour,

Essaie ainsi.

A te relire.

Cdlt.

Option Explicit

Public Sub CopyData()
Dim ws As Worksheet
Dim lastRow As Long
Dim rCell As Range
Dim objChart As ChartObject, objChart2 As ChartObject
Dim rngX As Range, rngY As Range, rngZ As Range
Dim n As Long

    Application.ScreenUpdating = False
    Set ws = ActiveSheet

    With ws
        lastRow = .Cells(.Rows.Count, 2).End(xlUp).Row
        .Cells(3, 2).CurrentRegion.Copy
        .Cells(lastRow + 4, 2).PasteSpecial xlPasteValues
        Application.CutCopyMode = False
        Set rCell = Selection.Cells(1)
        lastRow = .Cells(.Rows.Count, 2).End(xlUp).Row
        n = lastRow - rCell.Row
        Set rngX = rCell.Offset(1).Resize(n)
        Set rngY = rCell.Offset(1, 2).Resize(n)
        Set rngZ = rCell.Offset(1, 3).Resize(n)
        Set objChart = .ChartObjects(1)
        Set objChart2 = objChart.Duplicate.Chart.Parent
        With objChart2
            .Left = rCell.Offset(, 5).Left
            .Top = rCell.Offset(, 5).Top
        End With
        With objChart2.Chart
            .SeriesCollection(1).XValues = rngX
            .SeriesCollection(1).Values = rngY
            .SeriesCollection(1).ErrorBar _
                    Direction:=xlY, _
                    Include:=xlBoth, _
                    Type:=xlCustom, _
                    Amount:=rngZ, _
                    minusvalues:=rngZ
        End With
    End With

    Set rngZ = Nothing: Set rngY = Nothing: Set rngX = Nothing
    Set objChart2 = Nothing: Set objChart = Nothing
    Set rCell = Nothing
    Set ws = Nothing

End Sub

Bonjour Jean-Eric,

Alors je ne comprends pas très bien ton code mais il fonctionne parfaitement !

Merci beaucoup !

Bonjour,

Ci-dessous la procédure commentée.

Pense à clore le sujet.

Cdlt.

Option Explicit

Public Sub CopyData()
'Déclaration des variables
Dim ws As Worksheet
Dim lastRow As Long
Dim rCell As Range
Dim objChart As ChartObject, objChart2 As ChartObject
Dim rngX As Range, rngY As Range, rngZ As Range
Dim n As Long
    'Optimisation procédure (gel affichage)
    Application.ScreenUpdating = False
    'Feuille active (U)
    Set ws = ActiveSheet

    With ws
        'Dernière ligne colonne B
        lastRow = .Cells(.Rows.Count, 2).End(xlUp).Row
        'Copie des données
        .Cells(3, 2).CurrentRegion.Copy
        .Cells(lastRow + 4, 2).PasteSpecial xlPasteValues
        Application.CutCopyMode = False
        '1ère. cellule de la sélection copiée
        Set rCell = Selection.Cells(1)
        'Dernière ligne colonne B
        lastRow = .Cells(.Rows.Count, 2).End(xlUp).Row
        'Nombre de lignes pour redimensionner les plages des axes du graphiques
        n = lastRow - rCell.Row
        'Initialisation des plages pour le graphique
        Set rngX = rCell.Offset(1).Resize(n)
        Set rngY = rCell.Offset(1, 2).Resize(n)
        Set rngZ = rCell.Offset(1, 3).Resize(n)
        'Initialisation des variables
        'Graphique initial à copier
        '(1) dans l'exemple car il n'y a qu'un graphique, sinon le nommer
        Set objChart = .ChartObjects(1)
        'Nouveau graphique
        Set objChart2 = objChart.Duplicate.Chart.Parent
        With objChart2
            'Position du graphique dans la feuille
            .Left = rCell.Offset(, 5).Left
            .Top = rCell.Offset(, 5).Top
        End With
        With objChart2.Chart
            'Axe X (colonne B)
            .SeriesCollection(1).XValues = rngX
            'Axe Y (colonne D)
            .SeriesCollection(1).Values = rngY
            'Barre erreur (colonne E)
            .SeriesCollection(1).ErrorBar _
                    Direction:=xlY, _
                    Include:=xlBoth, _
                    Type:=xlCustom, _
                    Amount:=rngZ, _
                    minusvalues:=rngZ
        End With
    End With
    'RAZ variables (on libère la mémoire utilisée)   
    Set rngZ = Nothing: Set rngY = Nothing: Set rngX = Nothing
    Set objChart2 = Nothing: Set objChart = Nothing
    Set rCell = Nothing
    Set ws = Nothing

End Sub

Merci pour ces explications, je commence à comprendre.

En revanche je ne trouve pas comment clôturer le sujet....

Re,

Allez, cherche un peu.

Rechercher des sujets similaires à "parametrer barres erreur vba"