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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Microsof...', 1758201388, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Microsoft/Office/Excel/macro/recording/index(84): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78