From the course: Excel: Learning VBA
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Create a subroutine - Microsoft Excel Tutorial
From the course: Excel: Learning VBA
Create a subroutine
- [Instructor] There are two main types of procedures that you can create in Excel VBA, subroutines and functions. In this movie, I will show you how to create a subroutine, which you can run in the Visual Basic Editor or from your worksheet. My sample file is 01_06_subroutine, and you can find it in the chapter one folder of the exercise files collection. In this workbook, I have some data on the only worksheet commission and I'm going to use in the subroutine that I create the value and cell C7. So remember C7 and I'm going to press Alt F11 to move to the Visual Basic Editor. I'm in the Visual Basic Editor and I don't have any code modules to work with, so I'll go up to the insert menu and click module. There we go. And now I can define the code that I want to use. The keyword for a subroutine is sub and then you can give it a name, so I'll call it calc commission, and then open and close parentheses. The…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
(Locked)
Introduce object-oriented programming3m 2s
-
(Locked)
Examine the Excel object model4m 14s
-
(Locked)
Work in the Visual Basic Editor6m 27s
-
(Locked)
Set VBA project properties4m 28s
-
(Locked)
Create, export, and delete code modules5m 54s
-
(Locked)
Create a subroutine3m 28s
-
Create a function5m 2s
-
(Locked)
Add comments to your code4m 47s
-
Run a VBA procedure5m 20s
-
(Locked)
Add code to a recorded macro3m 48s
-
(Locked)
-
-
-
-
-
-
-