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 techguruplus telegram group Join Our WhatsApp Group techguruplus whatsapp group
Nazim Khan - Author Image

Nazim Khan (Author) 📞 +91 9536250020
[MBA in Finance]

Nazim Khan is an expert in Microsoft Excel. He teaches people how to use it better. He has been doing this for more than ten years. He is running this website (TechGuruPlus.com) and a YouTube channel called "Business Excel" since 2016. He shares useful tips from his own experiences to help others improve their Excel skills and careers.

Leave a Comment