R
Raul
I have the following commands nested in a VBA loop to
generate a number of charts with lines on 2 axes. It
works but I'm sure there's a way to choose the desired
chart type initially and clean up this code. Any
suggestions will be greatly appreciated.
Set NewChart = Charts.Add
' Had to start off with chart type xlLineMarkers
' and apply the desired chart type later in the code
' to eliminate crashes.
NewChart.ChartType = xlLineMarkers
NewChrtName = VarName
NewChart.SetSourceData Source:=DataRngArray(cntr), _
PlotBy:=xlColumns
NewChart.Location Where:=xlLocationAsNewSheet, _
Name:=NewChrtName
' Had to use ActiveChart because the code failed when
' NewChart was used. This is where the desired chart
' type is applied.
ActiveChart.PlotArea.Select
ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, _
TypeName:= "Lines on 2 Axes"
NewChart.Axes(xlCategory, xlPrimary).CategoryType =
xlCategoryScale
NewChart.Axes(xlCategory, xlSecondary).CategoryType =
xlCategoryScale
' end of code snippet
Thanks,
Raul
generate a number of charts with lines on 2 axes. It
works but I'm sure there's a way to choose the desired
chart type initially and clean up this code. Any
suggestions will be greatly appreciated.
Set NewChart = Charts.Add
' Had to start off with chart type xlLineMarkers
' and apply the desired chart type later in the code
' to eliminate crashes.
NewChart.ChartType = xlLineMarkers
NewChrtName = VarName
NewChart.SetSourceData Source:=DataRngArray(cntr), _
PlotBy:=xlColumns
NewChart.Location Where:=xlLocationAsNewSheet, _
Name:=NewChrtName
' Had to use ActiveChart because the code failed when
' NewChart was used. This is where the desired chart
' type is applied.
ActiveChart.PlotArea.Select
ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, _
TypeName:= "Lines on 2 Axes"
NewChart.Axes(xlCategory, xlPrimary).CategoryType =
xlCategoryScale
NewChart.Axes(xlCategory, xlSecondary).CategoryType =
xlCategoryScale
' end of code snippet
Thanks,
Raul