My Photo

NEED HELP?

  • Do you need additional assistance? I'm here to help!

    Please contact me for information on my availability and rates.

Use Your Apps to the Max!


A Note on Microsoft 2003 vs 2007

  • The majority of my posts here feature Microsoft 2003. If you are looking for 2007 info, please visit the Microsoft Office website which has a wealth of information, or contact me for further assistance.

« Cleaning Up Your Data in Excel | Main | Using AutoCorrect and Find and Replace in Microsoft Word »

August 25, 2011

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00e55296580f883401127903fb3428a4

Listed below are links to weblogs that reference If / Then Statements in Excel: Using Logical Formulas:

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

Knitter

I understand how to use if,then statements but I'm having trouble with one point. I want to compare two numbers, let's say cells B2 and C2. I want to know if b2 is greater than c2, and then I want to have the value of the greater to be entered at d2. How do I get the value of a cell to display as the answer?
=if(b2>c2, [the value of b2], [the value of c2])

Kathy Layne

That's it exactly. Just remove 'the value of' and you've got it, Knitter. However, there is an even easier way than using an IF statement. Just use the formula MAX: =max(B2:C2)

Joshua Amann

I have question. I have two columns which are drop down lists.

For Example:
Column 1
A
B
C
D
E

Column 2
F
G
H
I
J

I want each combination to equal as follows automatically in the third column.

Example:

If A and F are selected the value in the third column will equal 1

If A and G are selected, the value will be 2

If A and H are selected, the value will be 4

If A and I are selected, the value will be 7

If A and I are selected, the value will be 11

If B and F = 3
If B and G = 5
If B and H = 8
If B and I = 12
If B and J = 16

C and F = 6
C and G = 9
C and H = 13
C and I = 17
C and J = 20

D and F = 10
D and G = 14
D and H = 18
D and I = 21
D and J = 23

E and F = 15
E and G = 19
E and H = 22
E and I = 24
E and J = 25

Hope this makes sense. Not sure how I would set this up! Any help on this would be GREATLY appreciated!

Mia Baum

I had been looking for how to purge my spreadsheets of "#DIV/O!" so thank you for the "" tip.

So just so I make sure I don't purge all actual "O"s in my spreadsheet, what is the logical argument to replace "#DIV/O!" with "" for my current if, then statements in my spreadsheets?

Thanks.

Kathy Layne

Dear Joshua, great question. It ties in several importance Excel concepts. You need to understand:
Named Ranges,
Data Validation, and
the function VLookup.

Start by creating a worksheet called 'Names + Formulas'
In Row 1 type field names Column 1, Column 2, Combination, and Total. In Column 1 enter A-E and F-I in Column 2. In Combination fill in all of the combinations you identified in your question. In Total , match the combinations you specified.

Once you have the basics set, name the ranges. Select A1:A6 and select Formulas>Define Name. Excel will automatically use the name from the header but will select the entire range from A1:A6. Change the definition to A2:A6 before clicking OK. Do the same for column 2. For the Combination and Totals, select the entire range, but we will manually name this range, so select only the data C2:D26 and name the range Matrix.

Now that we have the data, and the names, let's move on to the data validation. Start a new worksheet and name the headers Column 1, Column 2, and total. Select the entire column A by clicking the header then selecting Data>Data Validation. Select list and in the source field type =Column_1. Do the same for Column 2.

Now for the total. We want to do two things, we need to combine column1 and 2 to create the combination, then we need to lookup the appropriate total from the Matrix range. But as I have also stressed in the blog it looks very unprofessional to have a column of errors or zeros before we fill in the data.

So our formula might start to look a little scary, but we are just doing these three things. To combine the values in column 1 and column 2 we use A2&B2. We place this into the lookup as follows:

vlookup(A2&B2,Matrix,2,0)

Now, to make sure that we don't get errors or zeros we place the vlookup into an if/then as:

=if(B2<>"",vlookup(A2&B2,Matrix,2,0),"")

Now just format the three columns and how ever many rows you need as a table, and drag the formula in Total down to the bottom.
Hope this helps!

Kathy Layne

Dear Mia,

If you can tell me what your exact formula is that is returning an error I can say for sure, but it is likely something like the example in the article where you have filled in the sales data, but have not yet figured out costs so your gross profit margin is dividing by zero/blank.

In this case, you can use an if statement to confirm that all of the necessary fields are filled in prior to calculation, or you can simply make sure that if the formula returns an error (which you have found is happening) that it gives you a blank instead. Excel has a built in function for just this purpose called IFERROR.
=IFERROR((A2-B2)/B2,"")
This built-in formula knows what you are trying to do and eliminates the need to put the formula in as both the test and the result. So in words it reads: if the test (A2-B2/B2) is an error, then display a blank, otherwise show the answer to the formula. Since dividing by zero returns the error value div/0! Excel would instead show a blank.

Let me know if this makes sense!

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Comments are moderated, and will not appear until the author has approved them.