Solved

How to add the smallest of two columns in Excel

Posted on 2014-01-27
8
210 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 31

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
 
LVL 31

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 31

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 31

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now