![]() |
||||
|
|
||||
Nested
IF Function Macro
|
||||
| Excel 2007 |
Excel 2003 |
Home |
Macros Excel 2003 |
Excel 2010 |
| About Us |
Free Ebook |
Offline Training |
Blog |
Interactive Training |
|
|
Last time we saw how we can use a simple IF-Functio Macro to take care of two conditions. What if we wish to handle multiple conditions like grades based on marks ranges or discounts based on various quantities purchased or bonus based on a range of sales? Here we can use the nested-if function macros to automate the process of calculations or analysis. The code is given below and it's easy to understand. Instead of 'else' we use 'elseif' and for the last condition we use 'else'. You can have upto 64 nested IFs in Excel 2007. Sub how_to_use_nested_if() Range("D4") = Range("C4") * Range("B4") If Range("B4") >= 100 Then Range("E4") = Range("D4") * 0.15 ElseIf Range("B4") >= 50 Then Range("E4") = Range("D4") * 0.1 Else Range("E4") = Range("D4") * 0.05 End If Range("F4") = Range("D4") - Range("E4") Range("F4") = Round(Range("F4"), 2) End Sub |
|||
|
|
||||
| Excel 2007 | Excel 2003 | Macros Excel 2007 | Macros Excel 2003 | Excel 2010 |
| About Us | Free Ebook | Offline Training | Blog | Interactive Training |