# Subtracting cells

#### Asquare

##### New Member
I want to subtract cell D3 from cell D2 but only if cells B3 & B2 have the same value. if cells B3 & B2 are not equal, I want the formula to detect the next two cells that contain the same values and subsequently deduct their respective values in column D. In this case the values in cells B5 & B4 are not equal, hence the formula should check cells B5 & B6 and if they contain the same value deduct the values in cell D6 & D5 (D6 - D5).

 Column B Month Column D Value 900 01-Jul-15 8140 8140 900 01-Aug-15 14999 6859 900 01-Sep-15 20978 901 01-Jul-15 9000 901 01-Aug-15 14633 901 01-Sep-15 19715 902 01-Jul-15 8338 902 01-Aug-15 12799 902 01-Sep-15 17059 903 01-Jul-15 8913 903 01-Aug-15 13960 903 01-Sep-15 18475

<tbody>
</tbody><colgroup><col><col><col><col></colgroup>

<tbody>
</tbody><colgroup><col><col><col><col></colgroup>

<tbody>
</tbody><colgroup><col><col><col><col></colgroup>

### Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

#### Tetra201

##### MrExcel MVP
Is this what you need?

=IF(B3=B2,D3-D2,"")

#### Asquare

##### New Member
Not quite, When B3<>B2, I want the formula to search for the next consecutive cells in column B that contain the same values. say B3<>B2, so the formula should check if cell B3=B4 and deduct D4 from D3.

Thanks for the help.

#### Tetra201

##### MrExcel MVP
Then could you please post a sample dataset with all expected results?

#### Asquare

##### New Member
 Number Month End Value 123 Jul-15 5057.96 123 Aug-15 9319.94 4261.98 123 Sep-15 13035.12 3715.18 123 Oct-15 14216.97 1181.85 123 Nov-15 16025.78 123 Dec-15 19130.77 123 Jan-16 24595.73 123 Feb-16 28733.44 123 Mar-16 33127.77 123 Apr-16 37580.52 123 May-16 38464.11 123 Jun-16 41100.58 123 Jul-16 42997.01 123 Sep-16 48713.00 123 Oct-16 51867.08 123 Nov-16 52919.68 321 Jul-15 5592.34 321 Aug-15 9092.52 3500.18 321 Sep-15 12250.33 3157.81 321 Oct-15 16145.08 321 Nov-15 18845.56 321 Dec-15 19392.99 321 Jan-16 21799.56 321 Feb-16 26165.31 321 Mar-16 29292.05 321 Apr-16 32028.57 321 May-16 33023.38 321 Jun-16 35753.69 321 Jul-16 38326.16 321 Aug-16 42172.45 321 Sep-16 44858.02 321 Oct-16 47721.29 321 Nov-16 48432.14

<tbody>
</tbody><colgroup><col><col><col><col></colgroup>

#### Asquare

##### New Member
I am trying to calculate a value for every month. say august, the expected value will be end of Aug - end of Jul, July value should be ignored but I don't want the formula to depict that as July values will come automatic.

#### Tetra201

##### MrExcel MVP
It is still unclear why there are no Values for Number 123 from Nov-15 through Nov-16.
Same for Number 321 from Oct-15 through Nov-16.

#### Asquare

##### New Member
 Number Month End Value 123 Jul-15 5057.96 123 Aug-15 9319.94 4261.98 123 Sep-15 13035.12 3715.18 123 Oct-15 14216.97 1181.85 123 Nov-15 16025.78 1808.81 123 Dec-15 19130.77 3104.99 123 Jan-16 24595.73 5464.96 123 Feb-16 28733.44 4137.71 123 Mar-16 33127.77 4394.34 123 Apr-16 37580.52 4452.74 123 May-16 38464.11 883.59 123 Jun-16 41100.58 2636.48 123 Jul-16 42997.01 1896.42 123 Sep-16 48713.00 5715.99 123 Oct-16 51867.08 3154.08 123 Nov-16 52919.68 1052.60 321 Jul-15 5592.34 321 Aug-15 9092.52 3500.18 321 Sep-15 12250.33 3157.81 321 Oct-15 16145.08 3894.75 321 Nov-15 18845.56 2700.48 321 Dec-15 19392.99 547.43 321 Jan-16 21799.56 2406.57 321 Feb-16 26165.31 4365.75 321 Mar-16 29292.05 3126.74 321 Apr-16 32028.57 2736.52 321 May-16 33023.38 994.81 321 Jun-16 35753.69 2730.30 321 Jul-16 38326.16 2572.48 321 Aug-16 42172.45 3846.29 321 Sep-16 44858.02 2685.57 321 Oct-16 47721.29 2863.28 321 Nov-16 48432.14 710.85

<tbody>
</tbody><colgroup><col><col><col><col></colgroup>

There you go

#### Tetra201

##### MrExcel MVP
... There you go
Unless I am missing something, the formula from Post #2 does provide the expected results.

If needed, rounding to whole cents can be added like this:
=IF(B3=B2,ROUND(D3-D2,2),"")

#### Asquare

##### New Member
Tetra201 Thank you for your time and help.

Replies
2
Views
493
Replies
1
Views
370
Replies
4
Views
334
Replies
2
Views
619
Replies
2
Views
680

1,191,166
Messages
5,985,051
Members
439,935
Latest member
Monty238

### 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.

### Which adblocker are you using?

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

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