Saturday, April 20, 2019

Charts Change Chart Type/ Paste Chart as an Image/ Add Chart Title


Charts
Use these VBA codes to manage charts in Excel and save your lot of time. 
Change Chart Type
This code will help you to convert chart type without using chart options from the tab. All you have to do just specify to which type you want to convert. 
Below code will convert selected chart to a clustered column chart. There are different codes for different types, you can find all those types from here.
Sub ChangeChartType()
ActiveChart.ChartType = xlColumnClustered
End Sub
Paste Chart as an Image
This code will help you to convert your chart into an image. You just need to select your chart and run this code.
Sub ConvertChartToPicture()
ActiveChart.ChartArea.Copy
ActiveSheet.Range("A1").Select
ActiveSheet.Pictures.Paste.Select
End Sub
Add Chart Title
First of all, you need to select your chart and the run this code. You will get an input box to enter chart title.
Sub AddChartTitle()
Dim i As Variant
i = InputBox("Please enter your chart title", "Chart Title")
On Error GoTo Last
ActiveChart.SetElement (msoElementChartTitleAboveChart)
ActiveChart.ChartTitle.Text = i
Last:
Exit Sub
End Sub

No comments:

Post a Comment