Edit recorded macros - danielep71/VBA-PERFORMANCE GitHub Wiki
[Home]] ](/danielep71/VBA-PERFORMANCE/wiki/[[Tips-and-Tricks)
While a recorded macro can provide valuable insights into Excelโs VBA syntax and references, it is always better to avoid using all the code from a recorded macro.
It is likely to have a detrimental effect on performance, so always review the macro and edit down the code to ensure only essential executable lines remain.
Example: Change the cell (โC2โ) color to yellow and bold font.
Recorded Macro: If you record the macro, the code could look like this:
Sub Macro1()
'
' Macro1 Recorded Macro
'
Range(โC2โ).Select
Selection.Font.Bold = True
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End Sub
Written Macro: the recorded macro can also be written like this:
Sub Change_Cell_Font()
With Range(โC2โ)
.Font.Bold = True
.Interior.Color = 65535
End With
End Sub
[Home]] ](/danielep71/VBA-PERFORMANCE/wiki/[[Tips-and-Tricks)