How to write a VBA macro

If you know Visual Basic programming then you can create your own VBA macro and run from within Excel.

Follow the steps below:

1. On the Tools menu select Macros.

2. On the Macro submenu select Visual Basic Editor.

User defined1

3. You will be switched to Visual Basic Editor Menu.

User defined 2

4. On the Insert menu (Visual Basic Editor) select Module.

5. This will open the code window.

User defined 3

6. Type the Visual Basic code for your macro.

Here is a simple example. A macro to increment the variable i by 5 and write it to column 2 (Column B) in the next row :

Sub TestMacro()
Dim i As Integer, Row As Integer, Col As Integer
i = 0
Col = 2
For Row = 1 To 10
i = i + 5
ActiveSheet.Cells(Row, Col).Value = i
Next Row
End Sub

7. On the File menu click Close and return to Microsoft Excel.

8. Your new macro is now ready to be run.

To run your macro:

1. On the Tools menu select Macros. A list of available macros will be displayed.

2. Select your macro and click Run.

Applies to: Excel 2003

How to print more than one sheet in a workbook

To print more than one worksheet in a workbook then :

1. Select the worksheets you want to print.

  1. If the sheets to be printed are adjacent then click on the first one, press SHIFT then click the last one.
  2. If they are not then click on the first one, press CTRL then click the others one at a time.

2. In the File menu click Print.

3. The Print window will open.

4. At the bottom of the Print window find a section labeled: Print what .

5. Click on the radio button labeled: Active sheet(s) .

6. Click OK.

Applies to Excel 2003

How to copy or move worksheets between workbooks

To copy or move worksheets between workbooks follow these steps:

1. Switch to the workbook which has the sheet to be copied or moved.

2. in the Edit menu click Move or copy sheet.

3. The Move or copy dialogue will open.

4. In the To book drop down select the destination workbook. You can also choose to create a new workbook.

5. in the Before sheet list click where you want the sheet to be moved (position within the workbook).

6. Select the Create a copy check box if you want the worksheet to remain in the original workbook, or deselect it  to move the worksheet completely and delete it from the original workbook.

Applies to Excel 2003