How To Use IF Function Statements In Microsoft Excel?

in #programming7 years ago

"Everybody knows how flexible the IF statement is within a scripted program, but are you aware that you may use a lot of the identical reasoning on the inside of a cell in Microsoft Excel?”

BlogPostImage

Image Source

Everybody knows how flexible the IF statement is within a scripted program, but are you aware that you may use a lot of the identical reasoning on the inside of a cell in Microsoft Excel?

A fundamental meaning of an IF statement in the program is it allows you to output anything particular depending on the outcomes of several inputs. You can carry out completely various computations depending on the production of some other calculations. You can execute conditional formatting. You may also base your result on string queries of input cells.

If this appears to be complex, do not fret. Let us check out a couple of innovative tricks to use IF statements in Excel.

What Is an IF Statement in Excel?

BlogPostImage

Image Source

When many people think about utilizing an IF statement in Microsoft Excel, they think of VBA. It is because an IF statement is normally logic that is employed on the planet of programming. Nevertheless, this can be used exact same coding logic correct within the spreadsheet cell by itself.

Once you type =IF within the cell, you will see exactly what the syntax of the IF statement must look like to work properly. The essential necessity is simply a “logical test”. By default the result towards the cell is going to be TRUE or FALSE, however, you can personalize that by including extra parameters within the function.

How a Basic IF Function Works

BlogPostImage

Image Source

Initially, let us check out a simple IF function. As an example, I have four routines which I log associated with my vehicle. I record the particular date when some of four events occur: an oil change, vehicle repair, registration, or insurance plan renewal.

Let us say in the event the “Repaired” column has a “YES”, then I want the Event Type to get “REPAIR”. Or else it ought to be “NON-REPAIR”. The reasoning with this IF statement is very easy:

=IF(C2="YES","Repair","Non-Repair")

This can be helpful logic, but in this case, it does not truly make a lot of sense. All someone needs to do is a glance at “Repaired” column to recognize whether or not that date included a repair.

So, let us check out even more sophisticated IF function statements to find out if we are able to turn this column a bit more beneficial.

AND and IF Statements

BlogPostImage

Image Source

Much like within the regular program, occasionally to be able to analyze two or three conditions that rely on each other, you should utilize AND logic. This is also true here.

Let us define two new event types: Planned or Unplanned.

For this particular instance, we are heading to concentrate on only the Oil Change column. I understand that I usually schedule my oil changes on the second day of every month. Any oil change that is not on the second day of the month was an unplanned oil.

To distinguish these we have to use AND logic such as this:

=IF(AND(DAY(A2)=2,B2="YES"),"Planned","Unplanned")

This is very rewarding, but as you can tell there is a small logical defect. It functions for displaying when oil changes happen on anticipated dates – thee turn up as “Planned”. However, when the Oil Change is blank, the output ought to be blank. It does not seem sensible to return a result in these instances simply because no oil change actually happened.

To achieve this, we will proceed to the following innovative IF function lesson: nested IF statements.

Nested IF Statements

BlogPostImage

Image Source

Creating on the last function, you will have to include an additional IF statement within the initial IF statement. This ought to return a blank when the initial Oil Change cell is blank.

Here is what that statement appears like:

=IF(ISBLANK(B2),"",IF(AND(DAY(A2)=2,B2="YES"),"Planned","Unplanned"))

The statement is beginning to appear somewhat complicated, however, it is not when you take a close look. The first IF statement inspects if the cell within the B column is blank. Should it be, then it returns a blank, or “ ”.

Understandably, this can get awfully complicated. Then when you are nesting IF statements, constantly bring it one step at a time. Check individual IF statement logic before you bein nesting them with each other. Due to the fact that after you have some of these nested troubleshooting them could become a genuine headache.

OR Statements

BlogPostImage

Image Source

Now we are likely to strike up the logic merely a notch. Let us say that this time around what I would like to do is return “Yearly Maintenance” if the oil change or repair coupled with registration or insurance is completed simultaneously, but simply “Routine Maintenance” if just an oil change was completed. It may sound complex, however with the best IF statement logic it is not difficult whatsoever.

This type of logic necessitates the mixture of a nested IF statement and a few OR statements. Here is what that statement will look like:

=IF(OR(B2="YES",C2="YES"),IF(OR(D2="YES",E2="YES"),"Yearly Maintenance","Routine Maintenance"),"")

It is outstanding the type of complicated assessment you are able to carry out simply by mixing different logical operators within nested IF statements.

Results Based on Value Ranges

BlogPostImage

Image Source

It is frequently very helpful to transform value ranges into some type of textual outcome. This can be as easy as transforming a temperature from 0 to 50 degrees F into “Cold”, 50 to 80 as “Warm”, and anything over 80 as hot.

Instructors most likely have the most desire for this logic due to letter scores. Within the subsequent instance, we are going to discover how you can transform a numeric value to textual content according to just such a range.

Let’s say a teacher uses the following ranges to determine letter grade:

• 90 to 100 is an A
• 80 to 90 is a B
• 70 to 80 is a C
• 60 to 70 is a D
• Under 60 is an F

Here is how that type of multi-nested-IF statement will appear:

=IF(B2>89,"A",IF(B2>79,"B",IF(B2>69,"C",IF(B2>59,"D","F"))))

Every nest is the next range within the series. You need to simply be cautious to seal out the statement using the correct quantity of parenthesis or perhaps the function will not function properly.

As you have seen, this enables you to signify any number by means of a descriptive string. It will update instantly when the numeric value of the sheet actually changes.

Using IF-THEN Logic Is Powerful

BlogPostImage

Image Source

Being a computer programmer, you are already aware of the potency of IF statement. They allow you to automate logical evaluation into any computation. This is extremely powerful inside a scripting language, but as you can tell it is equally as powerful inside the cells of an Excel spreadsheet.

With a bit of creativeness, you could do some really remarkable stuff with IF statement logic as well as other formulas in Excel.

What type of distinctive logic have you ever develop making use of IF statements in Excel? Discuss your personal concepts and recommendations within the feedback area underneath!

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 62227.11
ETH 2400.78
USDT 1.00
SBD 2.50