Macro runs much slower when called from ribbon than directly in module

ValuationMan

New Member
Joined
Jun 30, 2017
Messages
49
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I have a sub that searches for cells with formulas that contain a specific string. When I execute the code directly from the module, it runs in about 1 second. If I execute the macro from the developer ribbon or use a shortcut, the time jumps up to 10 seconds. Has anybody seen that sort of issue before? I have searched for a while and can't find anything.

Code:
Sub savevalues()

'Turn off automatic calculations & screen updating significnatly improves performance
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False

Dim ws As Worksheet
Dim datacell As Range

'First For Loop goes through all sheets in workbook
'Second For Loop identifies all cells with formulas, tests if cell formula contains "companyaddin"
'If it does contain "companyaddin", add comment with formula text as the comment text, save as values

For Each ws In ActiveWorkbook.Worksheets
    For Each datacell In ws.Cells.SpecialCells(xlCellTypeFormulas)
        If datacell.Formula Like "*""companyaddin*" Then
            datacell.AddComment datacell.Formula
            datacell.Value = datacell.Value
        End If
    Next datacell
Next ws

'clears object variables, restores automatic calculations & screenupdate
Set ws = Nothing
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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