Macro executing at unintended times (DoEvents issue)?

RawlinsCross

Active Member
Joined
Sep 9, 2016
Messages
437
I have a summary userformwith 2 DTPickers and 12 picture frames. When the user selects datesand clicks on a command button (Update Graphs), a graphing macro updates allthe graphs (*no problem with the graphing macro so will leave out*). Thistakes a couple seconds so I thought it'd be fun to include a status bar(ufProgress). Found one on the web and it works in large part. Theonly problem is that the status bar macro activates at every possible event(opening any one the DTPickers before eventually picking a date), evenclicking anywhere on the useform).

I image this is because of the "DoEvents" part of theFractionComplete code? But even if I comment that out the problem doesn't go away.
I only want the charts to reload when I click on either the Update Graphscommand button or some additional command buttons (e.g. I have command buttonsfor each month of the year)



Summary Userform Activation (*note there are some member variables prefixed by'm' the declarations of which I'm leaving out for brevity*)

Code:
Private Sub Userform_Activate()
[COLOR=#222222][FONT=Calibri]Dim arr1 As Variant
Dim i As Integer

[/FONT][/COLOR]
[COLOR=#222222][FONT=Calibri]Application.ScreenUpdating = False
ufProgress.LabelProgress.Width = 0
ufProgress.Show

arr1 = Array("Ni", "Co", "Cu", "Fe","S", "Ca", "Mg", "Si", "Mn","Na", "Al", "Zn")[/FONT][/COLOR]
[COLOR=#222222][FONT=Calibri]For miCount = LBound(arr1) ToUBound(arr1)
    msDataIdentifier = msICP & arr1(miCount)
    Call MakeChartSummary
    FractionComplete ((miCount + 1) * 0.083)  '0.083because I have 12 elements (1/12 = 0.083)
    ufProgress.Repaint
Next miCount

[/FONT][/COLOR]
[COLOR=#222222][FONT=Calibri]Erase arr1[/FONT][/COLOR]
[COLOR=#222222][FONT=Calibri]Application.ScreenUpdating = True[/FONT][/COLOR]
[COLOR=#222222][FONT=Calibri]Unload ufProgress

[/FONT][/COLOR]
[COLOR=#222222][FONT=Calibri]End Sub
[/FONT][/COLOR]


FractionComplete Code

Code:
Sub FractionComplete(pctdone As Double)
With ufProgress
    .LabelCaption.Caption = Format(pctdone * 100,"0.0") & "% Complete"
    .LabelProgress.Width = pctdone * (.FrameProgress.Width)
End With
DoEvents
End Sub





 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK


I image this is because of the "DoEvents" part of the FractionComplete code?
That is highly unlikely

I
(*no problem with the graphing macro so will leave out*)

I don't think you can say that without testing your assumption. What happens if you comment out that subroutine as a test? Does the progress bar still activate for every possible event?

Code:
Private Sub Userform_Activate()
    Dim arr1 As Variant
    Dim i As Integer

    Application.ScreenUpdating = False
    ufProgress.LabelProgress.Width = 0
    ufProgress.Show

    arr1 = Array("Ni", "Co", "Cu", "Fe", "S", "Ca", "Mg", "Si", "Mn", "Na", "Al", "Zn")
    For miCount = LBound(arr1) To UBound(arr1)
        msDataIdentifier = msICP & arr1(miCount)

        'Call MakeChartSummary  '<--------------------------------------- comment out

        FractionComplete ((miCount + 1) * 0.083)      '0.083because I have 12 elements (1/12 = 0.083)
        ufProgress.Repaint
    Next miCount

    Erase arr1
    Application.ScreenUpdating = True
    Unload ufProgress
End Sub
 
Upvote 0
The macro is running exactly when you are telling it to run , this is because you have put it in the USERFORM_ACTIVATE event sub. so everytime you do any thin on the user form it will run. You need to move the code so that it runs when you click the "update graphs" So put in the same module as the code you have got for updateing graphs and call them both together.
 
Upvote 0

Similar threads

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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