An Excel VBA Tutorial
Although Microsoft Excel can be purchased individually, it is usually part of the Microsoft Office package offered by Microsoft. The software, used by various accountants and workers often using numbers, allows users to make calculations as needed. However, if you find yourself often performing a repetitive task, Excel offers a component known as "Visual Basic for Applications" that allows users to customize Excel for their needs. With VBA, you can create a tool known as a "Macro" which records the repetitive task and runs it with the simple click of a button.
- Difficulty:
- Moderate
Instructions
-
-
1
Open the Excel by double-clicking on its icon on your desktop. Select "File" and "Open" to open the desired Excel worksheet. Locate the worksheet on your system and select the worksheet. Click "Open" to open the worksheet in Excel.
-
2
Select the "Developer" tab and locate the "Visual Basic" option. Click on the option to start the Visual Basic editor.
-
3
Add a new module by selecting "Module" from the "Insert" menu.
-
4
Create a new sub-procedure by entering the desired code. For example, entering the following code will rename "Sheet1:"
Private Sub renameWorksheet()
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "first sheet in workbook"
End Sub
-
5
Select the "Macros" icon from the original Excel window that will open up the Macros dialog window.
-
6
Type in the desired name for your macro in the "Macro Name" box, such as "sheetRename." Select the "Create" button to begin creating your macro.
-
7
Run the procedure created in Step 4 by typing in the "Call" line of code followed by the Macro name, such as "Call sheetRename."
-
8
Return to the original Excel window and select "Macros." Click the "sheetRename" macro and select the "Run" button. This will run the selected macro and change the name of Sheet1 to "first sheet in workbook."
-
1