OaklandJim
Well-known Member
- Joined
- Nov 29, 2018
- Messages
- 855
- Office Version
- 365
- Platform
- Windows
There is a steep learning curve for me trying to figure out how to create an embedded chart.
I want to specify the chart title and y axis label for an embedded chart.
When I try to use .Caption = "Chart Title" I get an error as shown below.
Also shown are attempts at setting the y axis title with error messages.
Here is the relevant code.
I want to specify the chart title and y axis label for an embedded chart.
When I try to use .Caption = "Chart Title" I get an error as shown below.
Also shown are attempts at setting the y axis title with error messages.
Here is the relevant code.
VBA Code:
Set wsData = ThisWorkbook.Worksheets("Sheet1") '<= worksheet containing data
Set rAnchorCellData = wsData.Range("A1") '<= this is the cell containing the ECR header
Set cResults = wsData.Shapes.AddChart.Chart
With cResults
.Parent.Name = "ECR Counts"
'
.ChartType = xlColumnClustered
.SetSourceData Source:=wsData.Range("B2:F3")
' Error Mthod or data member not found
'.Caption = "ECR Counts"
.Axes(xlValue).MajorUnit = 1
' Error 424: Object required
' .Axes(xlCategory, xlPrimary).AxisTitle.Text = "ECRs"
End With
With wsChart.ChartObjects("ECR Counts")
.Top = rAnchorCellChartData.Offset(0, -1).Top
.Left = rAnchorCellChartData.Offset(0, -1).Left
' Error 438: Object does not support this property or method
' .Axes(xlCategory, xlPrimary).AxisTitle.Text = "ECRs"
End With