Solved

How to add the smallest of two columns in Excel

Posted on 2014-01-27
8
213 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 33

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 100 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 33

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 33

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 33

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

821 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