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

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…

Contents