Sum values based on condition

Patrick020

New Member
Joined
Mar 20, 2018
Messages
15
Hi everyone <o:p></o:p>
<o:p></o:p>
I would like to sum values which are in two columns – but only take values from column B if column C is empty.
<o:p></o:p>
<o:p></o:p>
To provide some context, Column C is actual spend and Column B is forecast spend. When comparing against budget I want to SUM actual spend where available, but if the data is notavailable then take the forecast spend figure.
<o:p></o:p>
<o:p></o:p>
Here is an example:
<o:p></o:p>
<o:p></o:p>
[TABLE="class: MsoTableGrid"]
<tbody>[TR]
[TD][/TD]
[TD="width: 64, bgcolor: transparent"]A<o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"]B<o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"]C<o:p></o:p>
[/TD]
[/TR]
[TR]
[TD="width: 64, bgcolor: transparent"]1<o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"][/TD]
[TD="width: 64, bgcolor: transparent"]Forecast <o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"]Actual <o:p></o:p>
[/TD]
[/TR]
[TR]
[TD="width: 64, bgcolor: transparent"]2<o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"]Item 1 <o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"]40,000<o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"]45,000<o:p></o:p>
[/TD]
[/TR]
[TR]
[TD="width: 64, bgcolor: transparent"]3<o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"]Item 2<o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"]50,000<o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="width: 64, bgcolor: transparent"]4<o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"]Item 3<o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"]50,000<o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="width: 64, bgcolor: transparent"]5<o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"]Item 4<o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"]25,000<o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="width: 64, bgcolor: transparent"]6<o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"]Item 5<o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"]30,000<o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"]40,000<o:p></o:p>
[/TD]
[/TR]
[TR]
[TD="width: 64, bgcolor: transparent"]7<o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"][/TD]
[TD="width: 64, bgcolor: transparent"][/TD]
[TD="width: 64, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="width: 64, bgcolor: transparent"]8<o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"]Total <o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"]210,000<o:p></o:p>
[/TD]
[TD="width: 64, bgcolor: transparent"][/TD]
[/TR]
</tbody>[/TABLE]
<o:p></o:p>
<o:p></o:p>
I need a formula in B8 - The answer here is 210,000 as we SUM the Forecast values in B3, B4, B5 (as they have no Actual figures) and the Actual values in C2, C6 (as they have Actuals).
<o:p></o:p>

Hopefully that is clear - would appreciate any help!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
if vba is allowed try this

Code:
Sub SumStuff()
Dim r As Range
Dim total As Long
total = 0
'change range here for your range if needed
For Each r In Range("B2:B6")
    If r.Offset(, 1).Value = "" Then
        total = total + r.Value
    ElseIf Not r.Offset(, 1) = "" Then
        total = total + r.Offset(, 1).Value
    End If
Next
'change location of sum if needed
Range("B8").Value = total

End Sub
 
Upvote 0
Hi,

Non-array formula, entered normally:


Book1
ABC
1ForecastActual
2Item 140,00045,000
3Item 250,000
4Item 350,000
5Item 425,000
6Item 530,00040,000
7
8Total210,000
Sheet64
Cell Formulas
RangeFormula
B8=SUM(SUMIF(C2:C6,"",B2:B6),C2:C6)
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,246
Members
452,623
Latest member
cliftonhandyman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top