Set the color of a series on a new chart in the worksheet

Asked

Viewed 908 times

0

In Vbaproject I have a row that selects a certain series from the chart

Sub MudaCor()
ActiveChart.SeriesCollection(n).Select
End Sub

Being "n" the serial number I need to select.

the series colors of a graph, whether bar or even line, excel determines for itself.

How to change the color of this series, using a line code in VBA, to the color I want??

Sub MudaCor()
    ActiveChart.SeriesCollection(n).Select
    ExemploSerie.Mudacor (???)
End Sub

1 answer

0


I made a script to generate a new chart, according to the defined color parameters and cells of a column, according to lines containing value in cellule.

The Function Contalinhas serves to detect where there are cells with values, to delimit the chart data:

 Function ContaLinhas(area As Range) As Long

    Dim celula As Range, TotalLinhas As Long
    TotalLinhas = 0
    For Each celula In area
        If celula <> "" Then
            TotalLinhas = TotalLinhas + 1
        End If
    Next
    ContaLinhas = TotalLinhas
End Function

Here I have the Range and the Colors of the defined graphics

Sub NovoGrafico()       


'Os dados estão contidos na coluna "A" (apenas como exemplo)

C = ContaLinhas(Range("A:A"))

'Cria um novo grafico com os parametros a serem definidos

    ActiveSheet.ChartObjects("Superar").Activate
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.SeriesCollection(1).Values = Range(Cells(2, 2), Cells(C, 2))
    ActiveChart.SeriesCollection(1).XValues = Range(Cells(2, 1), Cells(C, 1))
    ActiveChart.SeriesCollection(1).Interior.Color = RGB(255, 255, 255)
    ActiveChart.SeriesCollection(1).Border.Color = RGB(0, 0, 0)
End Sub

That is to say,

I have a script that creates a new graphic with the colors White and Black, respectively, Interior and borders.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.