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 - 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,…
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
-
-
-
-
-
Repeat a task using a For…Next loop5m 6s
-
(Locked)
Step through all items of a collection using a For…Each loop4m 37s
-
(Locked)
Repeat a task using a Do loop5m 47s
-
(Locked)
Execute code conditionally using an If…Then statement6m 48s
-
(Locked)
Select which action to take using a Case statement3m 42s
-
(Locked)
Challenge: Add logic to your code2m 52s
-
(Locked)
Solution: Add logic to your code4m 40s
-
-
-
-
-
-