how to use macros in excel

Microsoft Excel is a very handy tool many of us use for our daily calculations. It can be used in simple calculations to advanced data processing. Anybody who wants to master excel, should know how to use macros in Excel. Basically Excel macros can be used in two different situations.

1.You can use macros in Excel to automate repetitive task

If you happen to perform same set of calculations, formatting over and over again on different sets of data you can think of writing an excel macro to automate that process.

Consider the following example

For the above worksheet the data is entered after completion of an exam. Then the total, average marks and the final grade of each student should be calculated. At the same time the grade column should be conditionally format to highlight the failed students. All the above calculations should be repeated when marks for a new exam is entered. This is the unnecessary repetition and we can avoid it by writing an Excel macro.

2. To achieve some advanced functionality which is impossible using the standard functions in Excel, we can write an Excel macro.

Consider the following situation

Here the requirement is to check whether the employees work according to their work agreement. The agreement does not permit to work in two consecutive shifts. How can you highlight the violation of the agreement? You can’t use the excel functions available to accomplish this situation. The answer is to write an Excel macro.

In this article let’s see how we can record a macro to avoid the repetitive tasks.

Insert the Developer tab to the Ribbon

All macro related options are available in Developer tab of Excel 2007. To add the developer tab to the ribbon click Office Button ->Excel Options and select Show Developer tab in the Ribbon.

Now the Developer tab should appear on the Ribbon.

Record the macro

Now you can record your macro. Here what you will be doing is performing the actions that you want to perform on the data that you have entered. They may be formatting cells, conditionally formatting or calculations. You have to record them in the exact order in which they should run when the macro is run.

To record the macro click on Record Macro in the Developer tab. Then you will be asked to give a name to your macro and a shortcut key. The short cut key can be used to run the macro lator.

Recording the macro

 Now whatever you will be doing is recorded to the macro. Once you have completed recording click Stop Recording Macro to stop recording.

Run the Macro

Now everything is Ok and you can test your macro in action. Click on Macros in the Code group of Developer tab. All the macros that are available will be displayed. Select the macro you recorded just before and click Run. The macro will run and all the formatting and calculations will be done at once! That is so easy

More by this Author


Comments 3 comments

AndyOwl profile image

AndyOwl 5 years ago from UK

Good article. There's a blog which expands further on recording macros in Excel (particularly 2007/2010) at http://www.wiseowl.co.uk/blog/s137/recording-macro...


IndikaT profile image

IndikaT 5 years ago from Kandy,Sri Lanka Author

@AndyOwl,

Thanks for the comment and the recommended further reading.


AndyOwl profile image

AndyOwl 5 years ago from UK

Really sorry - link should have been http://www.wiseowl.co.uk/blog/s137/recording-macro... - full stop (or period to Americans) at end stopped previous link working!

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working