Incorporating Progress Bar into existing Userform

grimley2

New Member
Joined
Feb 1, 2022
Messages
9
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
I'm trying to incorporate a Status Bar into my existing userform as per this example:
Excel VBA Macro: Progress Bar While Macro is Running

This is the search in which I'm attempting to invoke the status bar, which results in an error "byref argument type mismatch" ...
VBA Code:
Private Sub cmbSearch_Click()
    Dim DataRange   As Range, FoundCell As Range
    Dim i, j        As Long
    Dim Search      As Variant
    Dim ws          As Worksheet
    j = 2
    Do Until Sheet2.Cells(j, 1).Value = ""
        j = j + 1
    Loop
    If j > 2 Then
        Sheet2.Activate
        For k = 2 To j - 1
            Sheet2.Rows(2).EntireRow.Delete
        Next
    End If
    Sheet1.Activate
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    Search = txtSearch.Text
    If Len(Search) = 0 Then Exit Sub
    If IsNumeric(Search) Then Search = Val(Search)
    j = 2
    i = 2
    
    OpenStatusBar
    
    Do Until Sheet1.Cells(i, 1).Text = ""
        Set DataRange = ws.Range(ActiveSheet.Cells(i, 1), ActiveSheet.Cells(i, 8))
        Set FoundCell = DataRange.Find(Search, LookIn:=xlValues, lookat:=xlPart)
        If Not FoundCell Is Nothing Then
            Sheet2.Cells(j, 1).Value = ws.Cells(i, 1)
            Sheet2.Cells(j, 2).Value = ws.Cells(i, 2)
            Sheet2.Cells(j, 3).Value = ws.Cells(i, 3)
            Sheet2.Cells(j, 4).Value = ws.Cells(i, 4)
            Sheet2.Cells(j, 5).Value = ws.Cells(i, 5)
            Sheet2.Cells(j, 6).Value = ws.Cells(i, 6)
            Sheet2.Cells(j, 7).Value = ws.Cells(i, 7)
            Sheet2.Cells(j, 8).Value = ws.Cells(i, 8)
            j = j + 1
        End If
        
        i = i + 1
        
    Loop
    Sheet2.Activate
    j = 2
    Do Until Sheet2.Cells(j, 1).Value = ""
        Call RunStatusBar(j + 1, Count)
        j = j + 1
        Count = Sheet2.Cells(Rows.Count, "A").End(xlUp).row
    Loop
    lstDisplay.ColumnCount = 8
    lstDisplay.ColumnHeads = False
    lstDisplay.List = Worksheets("DATA").Range(Worksheets("DATA").Cells(2, 1), Worksheets("DATA").Cells(j, 8)).Value
    txtSearch = lstDisplay.ListCount - 1 & " items found"
End Sub

This is what I'm using for the progress bar:

VBA Code:
Sub OpenStatusBar()
    
    With StatusBar
        .Bar.Width = 0
        .Frame.Caption = "0% Complete"
        .Show vbModeless
    End With
    
End Sub

Sub RunStatusBar(row As Integer, total As Integer)
    
    With StatusBar
        .BarWidth = 234 * (row / total)
        .Frame.Caption = Round((row / total) * 100, 0) & "% Complete"
    End With
    
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
When asking help for a runtime error please indicate which line of code is highlighted when the error occurs and you go into Debug mode.
 
Upvote 0
It's line 47 here,
VBA Code:
Call RunStatusBar(j + 1, Count)
 
Upvote 0
Change your parameters

Rich (BB code):
Sub RunStatusBar(row As Long, total As Long)
 
Upvote 0

Forum statistics

Threads
1,214,947
Messages
6,122,413
Members
449,082
Latest member
tish101

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top