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
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