Home > Software engineering >  name for excel graph problem with the vba generator
name for excel graph problem with the vba generator

Time:01-10

So I'm trying to use a name as range values to generate a graph chart. I used the code generator from excel and I got that :

Sub Macro_name_graph2()
'
' Macro_name_graph2 Macro
'

'
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.FullSeriesCollection(1).name = "=""data1_1"""
    ActiveChart.FullSeriesCollection(1).Values = "==test_macro.xlsm!data1_1ord"
    ActiveChart.FullSeriesCollection(1).XValues = "==test_macro.xlsm!data1_1abs"
End Sub

what I put in the actual chart was ='test_macro.xlsm'!data1_1ord and ='test_macro.xlsm'!data1_1abs

But not when I try to run it again, I have an error 1004 at ActiveChart.FullSeriesCollection(1).Values = "==test_macro.xlsm!data1_1ord"

So I tried to put ActiveChart.FullSeriesCollection(1).Values = "=='test_macro.xlsm'!data1_1ord" and it didn't work neither

CodePudding user response:

This worked for me (changed the name of the workbook for my testing):

Sub Macro_name_graph2()
   With ActiveChart.SeriesCollection.NewSeries
        .Name = "=Book1!data1_1"
        .Values = "=Book1!data1_1ord"
        .XValues = "=Book1!data1_1abs"
    End With
End Sub

Note the NewSeries method returns the added series, so you can use that return value in a With block.

  • Related