Format et position de label VBA

Bonjour,

Objectif :

Dans un graphe de type waterfall, je souhaite remplacer les étiquettes de données de la série 2 par les valeurs d'une série de cellules (Ca ca marche ok).

+

Si la valeur est positive, la mettre en bleu & Selection.Position = xlLabelPositionBelow

Si la valeur est négative, la mettre en rouge entre parenthèse & Selection.Position = xlLabelPositionAbove

Pour l'instant j'ai ça :

Sub Renomme()

X = Application.Count(Range(Cells(6, 4), Cells(6, 4).End(xlDown))) - 1

For i = 1 To X

D6 = Range(Cells(5 + i, 4), Cells(5 + i, 4)).Value

ActiveWorkbook.Sheets(1).Select

ActiveSheet.ChartObjects("TEST").Select

ActiveSheet.ChartObjects("TEST").Chart.SeriesCollection(2).Points(1 + i).DataLabel.Text = D6

Next i

End If

Merci d'avance !!

Amaury

Solution trouvée (édité) :

Sub Renomme()

Dim x As Integer
Dim i As Integer

x = Application.Count(Range(Cells(6, 4), Cells(6, 4).End(xlDown))) - 1

    For i = 1 To x

    D6 = Range(Cells(5 + i, 4), Cells(5 + i, 4)).Value * -1

    ActiveSheet.ChartObjects("TEST").Activate

           If D6<= 0 Then

            With ActiveChart.SeriesCollection(2).Points(1 + i)
                .HasDataLabel = True
                .DataLabel.Text = Format(D6, "#;(#)")
                .DataLabel.Position = xlLabelPositionBelow
                .DataLabel.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(192, 0, 0)

            End With

            Else

            With ActiveChart.SeriesCollection(2).Points(1 + i)
                .HasDataLabel = True
                .DataLabel.Text = Format(D6, "#;(#)")
                .DataLabel.Position = xlLabelPositionAbove
                .DataLabel.Format.TextFrame2.TextRange.Font.Fill.ForeColor.ObjectThemeColor = msoThemeColorAccent1

            End With

        End If

    Next i

End Sub
Rechercher des sujets similaires à "format position label vba"