Search notes:

Excel: Recording macros

Start and stop

Start to record a macro:
Stop the recording:
Alternatively, the recording of a macro can also be started or stopped with the keyboard shortcut ALT-L+R.

«Problems» with the macro recorder

Macros produced with the macro recorder make extensive use of the application.selection property and the range.select() method:
Sub Macro2()
'
' Macro2 Macro
'
 
'
    Range("B3").Select
    ActiveCell.FormulaR1C1 = "Price 1"
    Range("C3").Select
    ActiveCell.FormulaR1C1 = "22.3"
    Range("B4").Select
    ActiveCell.FormulaR1C1 = "Price 2"
    Range("C4").Select
    ActiveCell.FormulaR1C1 = "18.45"
    Range("C5").Select
    ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
    Range("C3:C5").Select
    Selection.NumberFormat = "$ #,##0.00"
End Sub
In most (if not all) cases, the combination first calling .select and then using selection. can be simplified with just one line of code:
option explicit
 
sub addPrices()
    with sheets(1)
        .range("b3") = "Price 1"
        .range("c3") =  22.3
        .range("b4") = "Price 2"
        .range("c4") =  18.45
        .range("c5").formulaR1C1 = "=sum(r[-2]c:r[-1]c)"
        .range("c3:c5").numberFormat = "$ #,##0.00"
    end with
end sub

See also

Showing the Developer tab on the Ribbon.

Index