VBA Code to Create a Doughnut Chart in Excel

VBA Code:

' VBA Code to Create a Doughnut Chart in Excel

Sub CreateDoughnutChart()
    Dim ws As Worksheet
    Dim rngData As Range
    Dim cht As ChartObject
    
    ' Set the worksheet to create the chart
    Set ws = ThisWorkbook.Worksheets("Sheet1") ' Replace with the name of your worksheet
    
    ' Set the range of data for the chart
    Set rngData = ws.Range("A1:B5") ' Replace with the range of your data
    
    ' Create a new chart object
    Set cht = ws.ChartObjects.Add(Left:=100, Width:=300, Top:=100, Height:=300)
    
    ' Set the chart type to doughnut
    cht.Chart.ChartType = xlDoughnut
    
    ' Set the source data for the chart
    cht.Chart.SetSourceData Source:=rngData
    
    ' Set other chart properties as needed
    
    ' Display a message
    MsgBox "Doughnut chart created."
End Sub


Check All VBA Codes

Join Our Telegram Group

Join the TechGuruPlus Telegram group

Join Our WhatsApp Group

Join the TechGuruPlus WhatsApp group
Nazim Khan, founder of TechGuruPlus.com

— Founder & Editor, TechGuruPlus.com
[MBA in Finance]

Nazim Khan has spent over ten years working with Excel, Tally and office documentation in accounts, finance and MIS roles. He has been running TechGuruPlus.com since 2016, where he publishes free editable templates for office work, and the YouTube channel Business Excel. He has trained more than 50,000 people online. Every template on this site is built and checked by him before it is published.

Contact  Â·  Excel Course

Leave a Comment