Do you know how to add a chart title using Macros in Excel? If you don’t, then don’t be worried. We are here to help you to achieve this task quickly. In this article, we will learn the steps to Add Chart Title using Macros (VBA) in Excel Office 365. Let’s get into this article.
Add Chart Title using Macros:
Follow the below steps to add chart title using Macros in Excel worksheet.
- In the below screenshot, you can see the example chart with some data. We are going to add a title to this chart using Macros.
- On the Developer Tab, select the Visual Basic option under the Code section.
- It will open a new window, where you need to paste the below code.
VBA code to add chart title
‘First, you have to select a chart
Sub AddChartTitle()
Dim titleText As Variant
On Error GoTo Last
‘Get the Chart title
titleText = InputBox(“Please enter the chart title”, “Chart Title Input”)
‘Set the title on the selected chart
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveChart.ChartTitle.Text = titleText
Last: Exit Sub
End Sub
- You need to save the code by selecting it. Then close the window.
- You have to open the sheet containing the data. On the Developer Tab, choose the Macros option in the Code section.
- Then, you need to make sure that your macro is selected and click the Run button.
- After that a new Chart Title Input window will open, you need to type the title that you want for your chart.
- Hit the OK button.
- Finally, you will see the added chart title on your chart in the worksheet as shown in the below image.
Wind-Up:
In the above article, you can easily understand the steps to Add Chart Title using Macros (VBA) in Excel Office 365. Feel free to share your queries/suggestions in the below comment section. Thanks for visiting Geek Excel. Keep Learning!
Top comments (0)