Chapter 1.3 - Run Code From A Module
Chapter 1.3 - Run Code From A Module
#1 Excel tutorial on the net Excel Introduction Basics Functions Data Analysis VBA 300 Examples Ask us
As a beginner to Excel VBA, you might find it difficult to decide where to put your VBA code. The Create a Macro
chapter illustrates how to run code by clicking on a command button. This example teaches you how to run Chapter < >
code from a module.
Create a Macro
1. Open the Visual Basic Editor.
Macro Recorder
FormulaR1C1
Macro Security
Protect Macro
Sub Cyan()
Download Excel File
runcodefromamodule.xls
End Sub
Note: a procedure is either a sub or a function. Learn more about functions and subs here, if you like. Follow Excel Easy
4. The sub changes the background color of your worksheet to cyan. To achieve this, add the following code
line.
Cells.Interior.ColorIndex = 28
Note: instead of ColorIndex number 28 (cyan), you can use any ColorIndex number.
5. Click Macros.
Note: code placed into a module is available to the whole workbook. That means, you can select Sheet2 or
Sheet3 and change the background color of these sheets as well. The Add a Macro to the Toolbar program
illustrates how to make a macro available to all your workbooks (Excel files). Remember, code placed on a
sheet (assigned to a command button) is only available for that particular sheet.
EXCEL EASY • FREE EXCEL HELP • COPYRIGHT (C) 20102017 • ALL RIGHTS RESERVED
MICROSOFT EXCEL TUTORIAL | HOW TO USE VBA | EXCEL FORMULAS | DROPDOWN LIST