Wednesday, August 17, 2022

Get started with recording macros to learn VBA code

Better way to learn VBA code is to record every move or action and check the recorded code. From here we can learn and modify the code to suit your need. 

To record macro:

  1. Under Developer tab Click at Record Macro.









  2. Under Record Macro give your Macro name.


















    Default name given is Macro1,2,3..... but we can rename to differentiate the function.
    Macro name must begin with letter, maximum character 255 and must not contains space, period (.), exclamation mark (!), or the characters @, &, $, # in the name.
    Detail we refer here:
    Microsoft Reference - Macro naming rules

    Note: Under this dialog box you can choose to store recorded macro under This workbook, New Workbook or Personal Macro Workbook and also create short cut key to run this macro later.

  3. Click OK to begin recording and continue your work in Excel as usual.

  4. Upon completed click at Stop Recording.


     






  5. Save this file under Excel Macro-Enabled Workbook(*.xlsm).
















 

 To playback recorded macro:

  1. Under Developer tab Click at Macros.









  2. Under Macro select Macro name: and click Run.






















    Note: Under this dialog box you can choose macros in This Workbook or All Open Workbook.

  3. All the step recorded before run automatically.

To check recorded code:

  1. Under Developer tab Click at Macros.









  2. Under Macro select Macro name: and click Edit.






















  3. Visual Basic Editor will open and show code.



















    The code will be under module, try to understand and edit the code and run again and again.

Practice makes perfect. Thank You.

No comments:

Post a Comment