Define the color of a series in a new chart in the worksheet

0

In VBAProject I have a row that selects a particular chart series

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

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

The colors of the series of a chart, whether of bars or even rows, excel determines by itself.

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

Sub MudaCor()
    ActiveChart.SeriesCollection(n).Select
    ExemploSerie.Mudacor (???)
End Sub
    
asked by anonymous 16.05.2017 / 15:59

1 answer

0

I made a script to generate a new graphic, according to the defined color parameters and cells of a column, according to lines that contain value in cell.

  

The function Contalinhas serves to detect where there are cells with values, to   delimit the data of the graph:

 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 Colors

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,

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

    
23.05.2017 / 18:49