Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to add the smallest of two columns in Excel

Posted on 2014-01-27
8
Medium Priority
?
219 Views
Last Modified: 2014-01-28
I have two columns, each containing either a number (zero is allowed) or a blank cell.  I want to get the total of all the numbers in column A except if there is a number in column B.
Example:
A     B
3
2     0
4     2
The total should be 3 + 0 + 2 = 5.
0
Comment
Question by:Stephan Gross
8 Comments
 
LVL 34

Expert Comment

by:Rob Henson
ID: 39812353
Formula in column C:

=IF(B2="",A2,B2)

Then add up column C

Thanks
Rob H
0
 
LVL 19

Expert Comment

by:Ken Butters
ID: 39812355
One way would be to add a third column.

Add a formula to cell C1 as : =IF(ISBLANK(B1),A1,B1)
then do a fill down on column 'C'

Now you can sum column C to get the answer you want.

A second way would be to write a VBA macro to add the column for you.  I can help with that solution if you'd rather do it that way.
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 400 total points
ID: 39812356
Try this ARRAY formula

=SUM(IF(B1:B3="",A1:A3,B1:B3))

To enter an array formula
Press Ctrl-Shift-Enter

After you enter the formula do you see braces around the formula in the formula bar?

If not then
After entering the formula
Select the formula cell
press F2
press Shift-Ctrl-Enter
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Expert Comment

by:Rob Henson
ID: 39812363
Going by the title, maybe you need the smallest of the two columns:

=IF(B2="",A2,min(A2,B2))

Can scenario arise where A is blank but B has number?
0
 
LVL 34

Expert Comment

by:Rob Henson
ID: 39812379
Looking at it, blank is ignored in the MIN function so just the following in column C will get desired result:

=MIN(A2:B2)

Then sum of column C

Thanks
Rob H
0
 

Author Closing Comment

by:Stephan Gross
ID: 39813537
Thanks to all but Syed's solution was the only one that didn't require me to add another column.
0
 
LVL 34

Expert Comment

by:Rob Henson
ID: 39814684
If its always the smallest of the pair, I don't believe Syed's will work when the smallest is in column A.
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39815236
Hi, Rob. You are right about the title but the description in the question is different and that is what I based my solution on waiting for feedback from the asker which came in the form of acceptance.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question