The macro I created is done and loops through each customer in a range successfully; "rngCust" is one column of cells with a different customer name in each cell "cust". This macro can take a long time to run so I am trying to insert a progress bar to display the percentage complete. I got several online examples to work when I copied them using their code, but I have not yet been able to incorporate it into my macro successfully, even with lots of research on forums and websites. It seems like I'm doing it right, but...I'm still new to VBA and I feel like I must be missing a key concept here.
The idea is for the progress bar to show the percent complete as it goes from each "cust" cell in "rngCust" to the next cell, basically each iteration of the loop should update it.
This is the last set of changes I have tried, and here I get the error msg 1004-"Method Range of Object Global Failed" on the lastrow= in the variable definition; I also get error 91-"object variable or with block variable not set" on the pctCompl= line with the progress calculation in the body of the macro.
Here's what I have so far:
The user form macro is:
Private Sub UserForm_Activate()
Call CreateCustomerInvoices
End Sub
The main macro CreateCustomerInvoices is:
Dim wb As Workbook
Dim ws As Worksheet
Dim rngBilling As Range
Dim erps As Worksheet
Dim rngERPsumm As Range
Dim rngCust As Range
Dim cust As Range
Dim pctCompl As Single 'this is the first line of new code for the user form, 'everything above this is from the completed macro which runs 'correctly
Dim lastrow As Long 'this is also for the user form
lastrow = Range("rngCust" & Rows.Count).End(xlUp).Row ' '=rngCust.End(xlUp).Row does not get an error here
'but I still get the one below
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Billing")
Set rngBilling = ws.Range("rngBilling")
Set erps = wb.Worksheets("ERP Summary")
Set rngERPsumm = erps.Range("rngERPsumm")
Set rngCust = ws.Range("rngCust")
UserForm1.Show 'show user form- this works, the user form comes up
'LOOP for each cust in rngCust:
For Each cust In rngCust.Columns(1).Cells 'to look at a cell in each row of 'the first column of range
'this is the user form part:
pctCompl = cust / lastrow 'measure of progress, also tried '=cust/rngCust with no luck
With UserForm1
UserForm1.Text.Caption = pctCompl & "% Completed"
UserForm1.Bar.Width = pctCompl * 2
End With
DoEvents
'then it performs the rest of the macro here
'If statement
'IfElse
"IfElse
'Else
End If
Next cust
Unload UserForm1
End Sub
Any insight would be greatly appreciated.
Thank you.
Win10 Off 2013
The idea is for the progress bar to show the percent complete as it goes from each "cust" cell in "rngCust" to the next cell, basically each iteration of the loop should update it.
This is the last set of changes I have tried, and here I get the error msg 1004-"Method Range of Object Global Failed" on the lastrow= in the variable definition; I also get error 91-"object variable or with block variable not set" on the pctCompl= line with the progress calculation in the body of the macro.
Here's what I have so far:
The user form macro is:
Private Sub UserForm_Activate()
Call CreateCustomerInvoices
End Sub
The main macro CreateCustomerInvoices is:
Dim wb As Workbook
Dim ws As Worksheet
Dim rngBilling As Range
Dim erps As Worksheet
Dim rngERPsumm As Range
Dim rngCust As Range
Dim cust As Range
Dim pctCompl As Single 'this is the first line of new code for the user form, 'everything above this is from the completed macro which runs 'correctly
Dim lastrow As Long 'this is also for the user form
lastrow = Range("rngCust" & Rows.Count).End(xlUp).Row ' '=rngCust.End(xlUp).Row does not get an error here
'but I still get the one below
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Billing")
Set rngBilling = ws.Range("rngBilling")
Set erps = wb.Worksheets("ERP Summary")
Set rngERPsumm = erps.Range("rngERPsumm")
Set rngCust = ws.Range("rngCust")
UserForm1.Show 'show user form- this works, the user form comes up
'LOOP for each cust in rngCust:
For Each cust In rngCust.Columns(1).Cells 'to look at a cell in each row of 'the first column of range
'this is the user form part:
pctCompl = cust / lastrow 'measure of progress, also tried '=cust/rngCust with no luck
With UserForm1
UserForm1.Text.Caption = pctCompl & "% Completed"
UserForm1.Bar.Width = pctCompl * 2
End With
DoEvents
'then it performs the rest of the macro here
'If statement
'IfElse
"IfElse
'Else
End If
Next cust
Unload UserForm1
End Sub
Any insight would be greatly appreciated.
Thank you.
Win10 Off 2013