From the course: Excel: Learning VBA
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Execute code conditionally using an If…Then statement - Microsoft Excel Tutorial
From the course: Excel: Learning VBA
Execute code conditionally using an If…Then statement
- [Instructor] So far, most of this course's example files have contained subroutines or other code that run every time you call them. There will be times, though, when you want parts of your subroutines to run when a condition is true. You can use if then statements to execute code conditionally. To demonstrate, I will use the sample file named 03_04_IfThen, and you can find it in the Chapter Three folder of the exercise files collection. In this workbook I have a single worksheet, and in cell C5 I have the amount of a sale. And the question, which is stated in cell E4, is whether that amount qualifies for a bonus. You can do that fairly straightforwardly using an if function in Excel. So in cell E5, I'll type equal, and then if. And then in the parentheses, the logical test, and I will test to see if C5 is greater than or equal to 1400, so one four zero zero. I'll type comma. If it's true, I want to display yes.…
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
-
-
-
-
-
-