Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add a chart title in Excel VBA.
Excel
ActiveChart.HasTitle = True ActiveChart.ChartTitle.Text = [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the quotes around the title text
Using a variable name instead of a string
✗ Incorrect
In VBA, text strings must be enclosed in double quotes. So to set the chart title text, use a string like "Sales Data".
2fill in blank
mediumComplete the code to show the legend on the chart.
Excel
ActiveChart.HasLegend = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string like "Show" instead of True
Using a number instead of Boolean
✗ Incorrect
To display the legend, set HasLegend property to True.
3fill in blank
hardFix the error in the code to set the X-axis label.
Excel
ActiveChart.Axes(xlCategory).HasTitle = True ActiveChart.Axes(xlCategory).AxisTitle.Text = [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the label text
Using a variable name instead of a string
✗ Incorrect
The axis title text must be a string in quotes, like "X Axis Label".
4fill in blank
hardFill both blanks to set the Y-axis label and show its title.
Excel
With ActiveChart.Axes([1]) .HasTitle = [2] .AxisTitle.Text = "Revenue" End With
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using xlCategory for Y-axis
Setting HasTitle to False
✗ Incorrect
The Y-axis is xlValue. To show the title, HasTitle must be True.
5fill in blank
hardFill all three blanks to add a chart title, show legend, and set X-axis label.
Excel
With ActiveChart .HasTitle = [1] .ChartTitle.Text = "Annual Sales" .HasLegend = [2] With .Axes([3]) .HasTitle = True .AxisTitle.Text = "Month" End With End With
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting HasTitle or HasLegend to False
Using xlValue instead of xlCategory for X-axis
✗ Incorrect
To add a title and show legend, set HasTitle and HasLegend to True. The X-axis is xlCategory.