Create a macro by using Microsoft Visual Basic
1.If the Developer tab is not available, do the following to display it:
1.Click the Microsoft Office Button , and then click Excel Options.
2.In the Popular category, under Top options for working with Excel, select the Show Developer tab in the Ribbon check box, and then click OK.
2.To set the security level temporarily to enable all macros, do the following:
1.On the Developer tab, in the Code group, click Macro Security.
2.Under Macro Settings, click Enable all macros (not recommended, potentially dangerous code can run), and then click OK.
Note To help prevent potentially dangerous code from running, we recommend that you return to any one of the settings that disable all macros after you finish working with macros.
3.On the Developer tab, in the Code group, click Visual Basic.
4.If needed, in the Visual Basic Editor, on the Insert menu, click Module.
Note Modules are automatically created for all sheets in the workbook.
5.In the code window of the module, type or copy the macro code that you want to use.
6.To run the macro from the module window, press F5.
7.In the Visual Basic Editor, on the File menu, click Close and Return to Microsoft Excel when you finish writing the macro.
Source: Microsoft excel help