Subtotal while condition

RaulSan

New Member
Joined
Dec 13, 2015
Messages
3
Dear friends,

Is there any formula or VBA Code that allows me to subtotal a group of cells based on their cell background color but as enlisted in the "Desired formula" column as follows:

D4 Subtotals D5:D8
D5 Subtotals D6
D7 Subtotals D8

D6 And D8 Are data captured manually

Thanks a lot i hope this is easy to understand.

Thanks in advance.
[TABLE="class: grid, width: 790"]
<tbody>[TR]
[TD]Cell
[/TD]
[TD]C
[/TD]
[TD] D
[/TD]
[TD] E
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Reference
[/TD]
[TD]Code
[/TD]
[TD] Amount
[/TD]
[TD]Formula (Using Cell Reference)
[/TD]
[TD]Description
[/TD]
[TD]Cell Color
[/TD]
[TD]Desired Formula
[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]1
[/TD]
[TD] 20.00
[/TD]
[TD]=SUBTOTAL(9,D5:D8)
[/TD]
[TD]Second Subtotal (Range: 1:1 to 1.2.1)
[/TD]
[TD]Cell Color: Yellow
[/TD]
[TD]Subtotal til the next yellow cell
[/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD]1.1
[/TD]
[TD] 10.00
[/TD]
[TD]=SUBTOTAL(9,D6)
[/TD]
[TD]First Subtotal (Range 1.1.1)
[/TD]
[TD]Cell Color: Green
[/TD]
[TD]Subtotal til the next green cell
[/TD]
[/TR]
[TR]
[TD]6
[/TD]
[TD]1.1.1
[/TD]
[TD] 10.00
[/TD]
[TD]DATA INPUT
[/TD]
[TD]Data Captured Manually
[/TD]
[TD]Cell Color: No Color
[/TD]
[TD]No formula
[/TD]
[/TR]
[TR]
[TD]7
[/TD]
[TD]1.2
[/TD]
[TD] 10.00
[/TD]
[TD]=SUBTOTAL(9,D8)
[/TD]
[TD]First Subtotal (Range 1.2.1)
[/TD]
[TD]Cell Color: Green
[/TD]
[TD]Subtotal til the next green cell
[/TD]
[/TR]
[TR]
[TD]8
[/TD]
[TD]1.2.1
[/TD]
[TD] 10.00
[/TD]
[TD]DATA INPUT
[/TD]
[TD]Data Captured Manually
[/TD]
[TD]Cell Color: No Color
[/TD]
[TD]No formula
[/TD]
[/TR]
[TR]
[TD]9
[/TD]
[TD]2
[/TD]
[TD] 20.00
[/TD]
[TD]=SUBTOTAL(9,D10:D13)
[/TD]
[TD]Second Subtotal (Range: 2.1 to 2.2.1)
[/TD]
[TD]Cell Color: Yellow
[/TD]
[TD]Subtotal till the next yellow cell
[/TD]
[/TR]
[TR]
[TD]10
[/TD]
[TD]2.1
[/TD]
[TD] 10.00
[/TD]
[TD]=SUBTOTAL(9,D11)
[/TD]
[TD]First Subtotal (Range 2.1.1)
[/TD]
[TD]Cell Color: Green
[/TD]
[TD]Subtotal til the next green cell
[/TD]
[/TR]
[TR]
[TD]11
[/TD]
[TD]2.1.1
[/TD]
[TD] 10.00
[/TD]
[TD]DATA INPUT
[/TD]
[TD]Data Captured Manually
[/TD]
[TD]Cell Color: No Color
[/TD]
[TD]No formula
[/TD]
[/TR]
[TR]
[TD]12
[/TD]
[TD]2.2
[/TD]
[TD] 10.00
[/TD]
[TD]=SUBTOTAL(9,D13)
[/TD]
[TD]First Subtotal (Range 2.2.1)
[/TD]
[TD]Cell Color: Green
[/TD]
[TD]Subtotal til the next green cell
[/TD]
[/TR]
[TR]
[TD]13
[/TD]
[TD]2.2.1
[/TD]
[TD] 10.00
[/TD]
[TD]DATA INPUT
[/TD]
[TD]Data Captured Manually
[/TD]
[TD]Cell Color: No Color
[/TD]
[TD]No formula
[/TD]
[/TR]
[TR]
[TD="colspan: 2"]Grand Total
[/TD]
[TD] 40.00
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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