Macro fast when F5 from VBE but 5x slower with form button, activeX button, shortcut key and macro dialogue box, why?

JZG

New Member
Joined
Jun 24, 2020
Messages
7
Office Version
  1. 2010
Platform
  1. Windows
The title says it all. This is not about tips to make my code run faster. I routinely run a "Turn Stuff Off" before and a "Turn Stuff On" after the main code.

The question is: When I run the same code from F5 in the VBE vs All Ways to CALL the code, why are all the other ways 5 times slower?

F5 = 5 sec
vs
form button = 26 sec
activeX = 26 sec
ctrl + sft + Q = 26 sec
selecting macro from the macro dialog box = 26 flipping sec
 
I just noticed the F5 (fast method) used 28% of CPU and finished the script in 5 sec. I selected the same macro through the Macros selection box and it used 6-7%. The macro is iterating over 10 bits of data and with each iteration the % CPU would go from 0 to 7% and at times the status read "Not Responding".
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
In that case I don't know. As I said I've never noticed that behaviour.
 
Upvote 0
So, looks as if the slow-down is happening where I've used arrays. Here is an example of one:

VBA Code:
Dim arrMarkers As Variant
arrMarkers = shRPT.Range("M60:CZ70").Value

For i = LBound(arrMarkers, 1) To UBound(arrMarkers, 1)

    If arrMarkers(i, 1) <> Empty Then

        k = 75

        For j = LBound(arrMarkers, 2) To UBound(arrMarkers, 2)

            Marker = arrMarkers(1, j)
            a1 = arrMarkers(i, j)
            a2 = arrMarkers(i, (j + 1))
            shRPT.Cells(k, 1).Value = Marker
            If i <> 1 Then
            shRPT.Cells(k, m).Value = a1
            shRPT.Cells(k, n).Value = a2
            End If
            k = k + 1

        j = j + 1
        Next j

    End If

    m = m + 2
    n = n + 2

Next i

I also took an older version of this macro and timed F5 from the editor vs the keyboard shortcut and the time was equal. So, seems that excel working as expected.
 
Upvote 0

Forum statistics

Threads
1,214,657
Messages
6,120,764
Members
448,991
Latest member
Hanakoro

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