Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

VBA Codes — Record Macro

 

There are two most com­mon ways to write VBA codes,  they are–

  • Record the MACRO.
  • Write it in VBA Edi­tor from scratch.

Obvi­ously it’s easy to record the Macro and use it but there are cer­tain dis­ad­van­tages when you record the Macro like size of the script goes huge which makes it bit dif­fi­cult to cus­tomize it if needed, When we have to deal with the dynamic con­tents like get­ting the search results from Google, in such case its rec­om­mended to write the VBA.

1. Record a macro:

Record­ing a macro is one of the pow­er­ful fea­ture in Excel, It will record every action done by the user and it will auto­mat­i­cally gen­er­ate the code for the user and user gets the option to cre­ate a short­cut for the Macro so the next time when user wants to per­form the same action, all user has to do is to press the short cut. Record­ing of Macro is very use­ful when it comes to per­form the repet­i­tive task at mul­ti­ple times. It just not save the lot of time for the user but also it’s an very effec­tive way to make the actions error free. User also has priv­i­lege to cus­tomize the recorded code as per the requirements.

In excel 2007:

Step 1 : View -> Select Macros

Excel-VBA-MACRO-- Record Macro - 1

Excel-VBA — Record Macro — 1

Step 2: Select Record Macro

Excel-VBA-MACRO-- Record Macro - 2

Excel-VBA — Record Macro — 2

  • You will see the a dia­log box “Record Macro” where you to fill the fol­low­ing details
  1. Enter “First­Macro” as name and Short­cut key as Ctrl+w
  2. User can be very spe­cific for which Work­Sheet or Work­Book he wants to cre­ate Macro
  3. User can pro­vide some details about the macro but its optional.
  4. Hit OK and now macro is record­ing is every activ­ity done by the user.
Excel-VBA-MACRO-- Record Macro - 3

Excel-VBA– Record Macro — 3

Here we have put some val­ues in Excel and Cal­cu­lat­ing the Avg Age of the stu­dents and this entire process is recorded.

For stop­ping the Macro recording

View-> Macro-> Stop Recording

Excel-VBA-- Record Macro - 2

Excel-VBA– Record Macro — 4

Now when­ever we want to repeat the entire action all we need to is press the Short­cut key ( Ctrl + w) which we had cre­ated before we started the recording.

We can also see the recorded code in Visual Basic Edi­tor. Press “AltF11” and VB Edi­tor will be displayed

VBAProject(Book1)->Expand Mod­ules Folder-> Dou­ble Click on Module1

Excel-VBA-MACRO-- Record Macro - 5

Excel-VBA-Record Macro — 5

You may also like...

2 Responses

  1. Manoj badgujar says:

    good one

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: