How long macro takes keeps changing

PTP86

Board Regular
Joined
Nov 7, 2009
Messages
86
Hi

I've got a macro that uses the options selected on a user form.

Is there any common reasons other than computer/network performance, for why my macro in one instance takes 20 seconds to run and in another instance with exactly the same options selected on the userform it takes 240 seconds?

Thanks
 

Some videos you may like

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

pbornemeier

Well-known Member
Joined
May 24, 2005
Messages
3,882
If any of the options deal with establishing printer settings that is not unlikely, although somehwat extreme.

Open a text file then put a bunch of statements that write an identifier and the amount of time since the last time you wrote any identifier to the text file. Run your code a few dozen times and analyze which statements are causing the variable delay.

Code:
    'Start of block to add at start of code
    Dim dteOldTime As Date
    Dim dteNewTime As Date
    Dim dteDiff As Date
    Dim iOpenFile As Integer
    Dim sPath As String
 
    dteNewTime = Now
 
    iOpenFile = FreeFile
    If sPath = "" Then sPath = Environ("TEMP")
    Open sPath & "\CodeBench.txt" For Append As iOpenFile
    sPath = ThisWorkbook.Path
    'End of block to add at start of code
 
 
 
    'Place next two code lines at multiple places in code with
    'MARKER changed to indicate where theline is in the code
    dteOldTime = dteNewTime: dteNewTime = Now: dteDiff = DateDiff("s", dteOldTime, dteNewTime)
    Write #iOpenFile, "MARKER", dteOldTime, dteNewTime, Format(dteDiff, "0")
 
    Close iOpenFile 'Add at end of code
 

Watch MrExcel Video

Forum statistics

Threads
1,122,469
Messages
5,596,322
Members
414,053
Latest member
Dual Showman

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
Top