VBA Code to Create a Progress Bar in Excel

VBA Code:

' VBA Code to Create a Progress Bar in Excel

Sub CreateProgressBar()
    Dim ws As Worksheet
    Dim rng As Range
    Dim progressBar As Shape
    Dim progressCell As Range
    Dim progressValue As Double
    
    ' Set the worksheet and range for the progress bar
    Set ws = ThisWorkbook.Worksheets("Sheet1") ' Replace with the name of your worksheet
    Set rng = ws.Range("A1") ' Replace with the cell where you want to position the progress bar
    
    ' Set the range for the progress value
    Set progressCell = ws.Range("B1") ' Replace with the cell containing the progress value
    
    ' Get the progress value from the cell
    progressValue = progressCell.Value
    
    ' Create the progress bar shape
    Set progressBar = ws.Shapes.AddShape(msoShapeRectangle, rng.Left, rng.Top, rng.Width * progressValue, rng.Height)
    
    ' Customize the progress bar appearance
    With progressBar
        .Fill.ForeColor.RGB = RGB(0, 255, 0) ' Green color
        .Line.Visible = False
    End With
    
    ' Adjust the shape properties to match the progress value
    With rng
        progressBar.Left = .Left
        progressBar.Top = .Top
        progressBar.Width = .Width * progressValue
        progressBar.Height = .Height
    End With
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