VBA - Sub runs slower using shortcut key or F5 in VBE

mystic2k

New Member
Joined
Nov 2, 2006
Messages
27
Here's a really strange one - I have a set of macros that perform simple show/hide operations on a set of columns. Here's one of these macros, the others are very similar (I'm not including the code of all subs/functions being called because I reckon it's not relevant, but will be glad to do so if needed) :

Code:
Sub EditCurves()

    If RangeCheck() = False Then Exit Sub

    Application.ScreenUpdating = False
    ActiveSheet.Unprotect
    
    ShowColumns "edit"
    ShowButtons False, True, True
    CopyValues
    
    ActiveSheet.Range("toggle_edit").Value = "edit"
    ActiveCell.Offset(0, 1).Select
    
    ActiveSheet.Protect
    Application.ScreenUpdating = True

End Sub

When I execute this code using a Forms button, it runs very quickly (< 1 second).
But when I run it from a shortcut key (e.g. CTRL+SHIFT+K) or using F5 in VBE, there's a significant delay - I can see the "hourglass pointer" for several seconds while it executes.


I've tried unloading all add-ins, no change.
I've tried to write some "checkpoints" to a log file with timestamps to check which part of the code was at fault, but it appears the entire sub just runs slower (instead of seeing all my timestamps in the same 1-second window, they were evenly spread within a 5-second window).

I'm running out of ideas and this is driving me nuts - my application relies on swift response from shortcut keys for a good user experience so I really need to figure this out. Would love to hear any ideas/suggestions!!

Excel 2010 / Windows 7
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
It is certainly strange, but I notice a seemingly slight delay on a little macro if I run it with Alt-F8. I wonder what overheads Excel is putting on it then. No solution though.
Does it help if you set Application.EnableEvents =false/true at start / end?
 
Upvote 0

Forum statistics

Threads
1,215,433
Messages
6,124,861
Members
449,195
Latest member
MoonDancer

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