Running time error '91' The object variable or the with block variable has not been defined

0

I do not know how to work very well with excel, I have to make a graph using buttons and gave this error

Sub logs_acumulador()
'
' logs_acumulador Macro
'

'
    ActiveChart.SetSourceData Source:=Range( _
        "db_performance.producao[[#All],[logs_acumulador]]")
    ActiveChart.SeriesCollection(1).XValues = "=Plan1!$A$5:$A$124"
End Sub
    
asked by anonymous 02.04.2018 / 14:56

1 answer

2

You must first add the graphic so that it is recognized as an object, and in the object you can configure the range from which the information comes:

Use a line similar to this one with the chart that best fits your data. In this case, it is a bar chart:

ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select

Complete code:

Sub logs_acumulador()
'
' logs_acumulador Macro
'

'
    ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select 'gráfico de barras
    ActiveChart.SetSourceData Source:=Range( _
        "db_performance.producao[[#All],[logs_acumulador]]")
    ActiveChart.SeriesCollection(1).XValues = "=Plan1!$A$5:$A$124"
End Sub
    
02.04.2018 / 21:00