我有找到所有具有特定公式的单元格的代码。该代码将注释添加为公式,并将公式作为注释文本。然后该单元格等于该值。当我直接在模块中执行代码时,大约需要1秒钟。如果我从开发人员功能区执行宏,则需要15秒。有人看过吗?我已经包含了下面的代码,但是我不确定这是否是问题所在。
'Turn off automatic calculations & screen updating significnatly improves performance
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Dim ws As Worksheet
Dim datacell As Range
Dim wb As Workbook
Set wb = ActiveWorkbook
Dim sheetarray As Sheets
Set sheetarray = wb.Sheets(Array("Fun Discount", "Multiples", "EV Calc", "Beta", "Bandaid", "Company Reference", "Input"))
'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 sheetarray
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
Set sheetarray = Nothing
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True