Complete the code to create a pie chart from data in cells A1 to B5.
ActiveSheet.Shapes.AddChart2(251, [1], Left:=100, Top:=50, Width:=300, Height:=300).Chart.SetSourceData Source:=Range("A1:B5")
The xlPie constant creates a pie chart in Excel VBA.
Complete the code to add a doughnut chart using the ChartType property.
Dim cht As Chart Set cht = ActiveSheet.Shapes.AddChart2(251).Chart cht.ChartType = [1]
The xlDoughnut constant sets the chart type to a doughnut chart.
Fix the error in the code to set the chart title for a pie chart.
ActiveSheet.ChartObjects(1).Chart.ChartTitle.Text = [1]
The chart title text must be a string enclosed in double quotes in VBA.
Fill both blanks to create a pie chart and set its data source to range A1:B4.
Dim chartObj As ChartObject Set chartObj = ActiveSheet.ChartObjects.Add(Left:=100, Top:=50, Width:=300, Height:=300) chartObj.Chart.ChartType = [1] chartObj.Chart.SetSourceData Source:=Range([2])
Use xlPie for pie chart type and specify the data range as a string with quotes.
Fill all three blanks to create a doughnut chart, set its data source, and add a chart title.
Dim chObj As ChartObject Set chObj = ActiveSheet.ChartObjects.Add(Left:=50, Top:=50, Width:=350, Height:=350) chObj.Chart.ChartType = [1] chObj.Chart.SetSourceData Source:=Range([2]) chObj.Chart.ChartTitle.Text = [3]
Use xlDoughnut for doughnut chart, specify the data range as a string, and set the title text with quotes.
