Forum

How to check the VB...
 
Notifications
Clear all

How to check the VBA code for Excel Chart?

3 Posts
2 Users
0 Reactions
128 Views
(@Anonymous)
Posts: 0
New Member Guest
 

Hi,

Does anyone can share with me how to get the VBA code for excel chart?

Example: 

Sub ChartType()
Dim ChtObj As ChartObject
For Each ChtObj In ActiveSheet.ChartObjects
ChtObj.Chart.ChartType = xlColumnClustered
Next ChtObj
End Sub

Question: How to know the chart name? Bar chart, pie chart & etc?

Thank you.

 
Posted : 01/10/2020 12:56 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi,

Are you asking how to find out the chart type for all charts on the active sheet?

Change the For Each loop to this

   For Each ChtObj In ActiveSheet.ChartObjects

      Debug.Print ChtObj.Chart.ChartType

   Next ChtObj

It will print the chart type value/code into the Immediate window.  You can get the chart type values from here

https://docs.microsoft.com/en-us/office/vba/api/excel.xlcharttype

If this relates to a specific problem, please attach the workbook.

Regards

Phil

 
Posted : 01/10/2020 2:24 am
(@Anonymous)
Posts: 0
New Member Guest
 

Thank you Phil. Yes i am looking for excel chart type enumeration in VBA. The link that you sent is very useful. thank you.

 

 
Posted : 01/10/2020 10:08 pm
Share: