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