Hello all you Excel experts!
Code below, problematic line marked with red.
I am writing a piece of code to list the title, axis titles onto a list for further programming.
I have run into a weird little problem. In my IF statement to see if the active chart has an axis title, the program fails if the chart type is one where axes are not applicable. I encountered this problem when the program came across a 3D pie chart.
I have tried including HasAxis (I think it is called) in the IF statement, but still had the error.
The solution I have made is to make a parent IF statement where I repeatedly use IF chart.type <> [type] for all the chart types I can think of that do not use axes. This solution works, but is not really elegant or sure. I have definitely left some out.
I was thinking, is there a better way to do this? Simplified code below.
For Each ws In Worksheets
If ws.ChartObjects.Count > 0 Then
For Each cht In ws.ChartObjects
cht.Activate 'Activates the chart for changes
'--- If the chart category axis has a title, it is written in the list
If ActiveChart.ChartType <> xl3DPie And ActiveChart.ChartType <> xl3DPieExploded And ActiveChart.ChartType <> xlBarOfPie And xlBubble And ActiveChart.ChartType <> xlPie Then
If ActiveChart.Axes(xlCategory).HasTitle = True Then
Sheets("TransArrCharts").Cells(pasterow, 1) = ActiveChart.Axes(xlCategory).AxisTitle.Caption
pasterow = pasterow + 1
End If
End If
Next cht
End If
Next ws
Thank you,
GregersDK
Bookmarks