Sunday, September 8, 2013

How to Record Macro to Automate Excel

Macro are the simple programs using to automate tasks/operations on the excel. They are developed using the programing language "Visual Basic for Applications"(VBA). This  based on Visual Basic. We can record macro on excel and use them later. You have to activate Developer Tab before you record a macro. If you Don't know how, Check my post about

"How to Enable Developer Tab"

Below table will be used to demonstrate the example for record macro.
Brand Item List Price Discount Selling Price
Nike Shoe $111.99 $111.99
Nike Socks $21.99
Adidas Shoe $58.74
Adidas Socks $16.99
Reebok Shoe $26.59
Copy above table and paste to cell A1 on blank sheet.

Start Record Macro

  1. Select cell E2.
  2. Then click on "Record Macro" in Developer Tab.
    Record Macro
  3. After that a new pop up window appears.
  4. Now you can change the name of macro and assign a shortcut key to launch this macro on later. For this example we set the macro name as "CopyMacro" and "Ctrl + Shift + A" as the shortcut key.
  5. Then click "OK". Now our macro is recording.

Record the Macro

Now we can simulate the actions to be recorded as the macro. Follow below steps to record a simple copy macro.
  1. Copy the cell E2 and paste it onto cell E3.
  2. Then Click on "Stop Recording" in developer tab to stop recording our macro.
  3. Done.
You have recorded the first ever macro recorded by you. Let's check how it's working.

Check the Recorded Macro

  1. Delete the cell E3
  2. Then enter the "Ctrl + Shift + A" to activate your macro.
Now you can see excel automatically copy cell E2 and paste into cell E3.

Relative References

If you properly inspect the Developer tab, you can see there is an option calling "Use Relative References". What is the use of that? Follow bellow steps and see the difference.
  1. Select Use Relative References Option
  2. Then Select cell E2.
  3. Now click on "Record Macro" in Developer Tab.
  4. Then a new pop up window appears.
  5. Now you can change the name of macro and assign a shortcut key to launch this macro on later. For this example we set the macro name as "CopyMacroNew" and "Ctrl + Shift + B" as the shortcut key.
  6. Then click "OK".
  7. After that Copy the cell E2 and paste it onto cell E3.
  8. Then Click on "Stop Recording".
  9. Then enter the "Ctrl + Shift + B"
See the difference. This time excel copies whichever cell you are selected and paste it into the relative position.

No comments:

Post a Comment

Featured Post

XLOOKUP in Excel: The Ultimate Guide to Dynamic Data Lookup

Excel is a powerful tool for analyzing data, but sometimes finding specific data points can be a headache-inducing task. That's where XL...