VBA Code to Create a Waterfall Chart in Excel

VBA Code:

Sub CreateWaterfallChart()
    Dim ws As Worksheet
    Dim chtObj As ChartObject
    Dim chtData As Range
    Dim cht As Chart
    
    ' Set the worksheet where you want to create the chart
    Set ws = ThisWorkbook.Sheets("Sheet1") ' Replace "Sheet1" with the desired worksheet name
    
    ' Define the range of data for the chart
    Set chtData = ws.Range("A1:C10") ' Replace "A1:C10" with the range of data for the chart
    
    ' Create a chart object on the worksheet
    Set chtObj = ws.ChartObjects.Add(Left:=100, Width:=400, Top:=100, Height:=300)
    
    ' Set the chart object's position and size
    With chtObj
        .Left = 100
        .Top = 100
        .Width = 400
        .Height = 300
    End With
    
    ' Set the chart object's chart type to waterfall
    Set cht = chtObj.Chart
    cht.ChartType = xlWaterfall
    
    ' Set the chart's data source
    cht.SetSourceData chtData
    
    ' Format the chart as needed
    ' (e.g., axis labels, title, legend, etc.)
    
    ' Add any additional formatting or customization
    
    ' Display the chart
    chtObj.Activate
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