Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple SUM question

Status
Not open for further replies.

Pudsters

Technical User
Mar 16, 2006
151
US
I want C1 to add A1+B1. (Told you it was simple!) But only if there is a value in both, A1 and B1, otherwise do nothing.

 
Look in Excel's help file at "IF worksheet function". There you will see that the arguments for the IF function are

[COLOR=blue white]IF(logical_test,value_if_true,value_if_false)[/color]

Your logical_test will be something like [COLOR=blue white]And(A1<>"",B1<>"")[/color] (there are many ways to test if those cells are blank, but this seems pretty straightforward for someone who isn't familiar with functions).

Your value_if_true will be [COLOR=blue white]A1+B1[/color].

Your value_if_false is whatever you want to do if either cell is empty. If you want C1 to just appear empty, then you can use [COLOR=blue white]""[/color].

Putting that all together, you get:
[COLOR=blue white]=If(And(A1<>"",B1<>""),A1+B1,"")[/color]

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ181-2886 before posting.
 
Thanks to both of you. I knew how to do the IF statement for one cell, I just couldn't figure out the proper syntax for two cells. I was putting the AND in the wrong spot.

Appreciate the explanation and not just the answer!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top