VBA Tip: Create a Progress Bar

Here's an example of a progress bar that can be created in VBA using a few simple controls:

progress bar excel vba

For this example, to give time to see the progress bar, 250,000 values will be entered in the cells, and the progress bar will move according to the progress:

Private Sub CommandButton1_Click()
    
    'Source: https://www.excel-pratique.com/en/vba_tricks/progress-bar
	
    Application.ScreenUpdating = False
    
    UserForm_demo.Height = 131.25

    counter = 0
    progress = 0
    
    For row = 1 To 5000
        For col = 1 To 50
        
            counter = counter + 1
            Cells(row, col) = row + col
            
            If counter Mod 2500 = 0 Then '=> will be executed 100 times
                
                progress = progress + 1
                Image_bar.Width = progress * 1.5
                Label_bar.Caption = progress & "%"
                DoEvents
                
            End If
            
        Next
    Next
    
    Application.ScreenUpdating = True
    UserForm_demo.Height = 142.5
    
End Sub
If needed, you can download the Excel file used here: progress-bar.xlsm

And as a bonus, here's the image used in this progress bar:

progress bar color