Tuesday, July 26, 2011

Microsoft Excel Visual Basic Tutorial


1. Click on the 'Alt' and 'F11' keys from within any Excel worksheet or workbook to open the Visual Basic Editor (VBE). You can also access the VBE by clicking on the 'Developer' tab and then clicking on 'Visual Basic.'
2. Click on the 'Insert' tab, and then click on 'Module' to open a blank window for your program.
3. Type the word 'Sub' (for subroutine) or 'Function' into the window, followed by the name of your program. For example, 'Sub italics()' is the first line of a subroutine called 'Italics.' If the VBA returns a result such as a number, it's a function. If it performs a task without returning anything, it's a subroutine.
4. Type an apostrophe on a new line, followed by a description of what the program is for. For example: ''this macro italicizes a highlighted cell.'
5. Type the body of your code starting on a new line. For example, to italicize a cell, type:'Selection.Font.Italic = True.'
6. Type 'End Sub' or 'End Function' on a new line, depending on if you defined a Sub or Function in Step 3.
7. Run the code by pressing the 'F5' key.

Blogger news