From the course: Excel: Learning VBA

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Select which action to take using a Case statement

Select which action to take using a Case statement - Microsoft Excel Tutorial

From the course: Excel: Learning VBA

Select which action to take using a Case statement

- [Instructor] If then statements let you determine which code segments to run based on rules you define. Unfortunately, they can be rather hard to read. If you want to run a brief segment of code and you want to test multiple conditions, you can use a case or case select statement, and in this movie, I will show you how to do that. My sample file is 03_05_Case and you can find it in the chapter three folder of the exercise files collection. In this workbook, I have a single worksheet, and you see in cell C5 that I have a sale amount, and my goal is to test that amount against various rules to see what type of commission, that is, what amount I want to pay. I have created a subroutine to do that in Excel VBA, so I'll press alt-F11, and there we have my code module, and that has my subroutine named select rate. At the top, I have a variable that will take in a value as a currency and then activate cell C5, and the total,…

Contents