From the course: Excel: Learning VBA
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Call a subroutine from another subroutine - Microsoft Excel Tutorial
From the course: Excel: Learning VBA
Call a subroutine from another subroutine
- [Instructor] One strength of Excel VBA is that you can run a subroutine from within another subroutine. And I'll tell you why that's so important in a moment, but first I will show you how to do it. My sample file is 06_04_Calling, and you can find it in the chapter six folder of the exercise files collection. This workbook has a single worksheet and on it I have values in row seven, so I have B7, C7, and D7. Let's say that I have created subroutines that will display the city and the state. To demonstrate, I'll press alt F11 to move to the Visual Basic Editor, and here is my code. At the top, I have two variables that can be used anywhere within this code module, and those are state and city as strings. And below that, I have what I'm calling my main routine and that is display info. So, it activates cell B7, and then it looks one column to the right and in the same row to get the state, and then two columns to the right…
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)
Turn off screen updating when you run a macro4m 21s
-
(Locked)
Use worksheet functions in a macro3m 12s
-
(Locked)
Acquire values using an input box or message box6m 55s
-
(Locked)
Call a subroutine from another subroutine3m 46s
-
(Locked)
Challenge: Add advanced elements to your workbook3m 35s
-
(Locked)
Solution: Add advanced elements to your workbook4m 1s
-
(Locked)
-
-