Conditional divide (divide if)

eendje

Board Regular
Joined
Nov 9, 2006
Messages
54
B C D
10 1 5
8 0 6
4 1 4

This is a short version of my sheet. Column C only contains 1 or 0. Column B and D all sorts of numeric values.

For each cell in column A I want to check if the corresponding cell in column C contains a 1 and if so, I want it to divide the corresponding cell in column B with that one of column D. If the value in column C is 0, it should return 0

So in the example above, Column A would have the values 2 (10/5), 0 (since C=0) and 1 (4/4).

To be more accurate, I want to use this formula inside another formula, something like:
=1-$A2+$A2*(B4/D4+B6/D6+...+...for all where column C has value of 1)

Can anyone assist me with this please? I looked a bunch but couldn't find the solution.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
=SUMPRODUCT(--(C1:C3=1),(B1:B3/D1:D3))
Change the ranges to fit your dataset, or consider using dynamic ranges
 
Upvote 0
=SUMPRODUCT(--(C1:C3=1),(B1:B3/D1:D3))
Change the ranges to fit your dataset, or consider using dynamic ranges

That does exactly what I need, thanks! :)

I remember now seeing the sumproduct formula being used in similar ways before and always found this quite strange. As if it is 'misused' somehow.

Can u explain what this does, cause I'm trying to wrap my head around it. For instance, the '--' what does that do?
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

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