Sum values based on indent

jocker_boy

Board Regular
Joined
Feb 5, 2015
Messages
83
Hi,

I want to sum values based on indent level in another column. Example:

[TABLE="width: 100"]
<tbody>[TR]
[TD][/TD]
[TD]text
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]A
[/TD]
[TD]0
[/TD]
[TD]9
[/TD]
[/TR]
[TR]
[TD]A.1
[/TD]
[TD]2
[/TD]
[TD]2
[/TD]
[/TR]
[TR]
[TD]A.2
[/TD]
[TD]4
[/TD]
[TD]4
[/TD]
[/TR]
[TR]
[TD]A.3
[/TD]
[TD]5
[/TD]
[TD]5
[/TD]
[/TR]
[TR]
[TD]B
[/TD]
[TD]0
[/TD]
[TD]3
[/TD]
[/TR]
[TR]
[TD]B.1
[/TD]
[TD]1
[/TD]
[TD]1
[/TD]
[/TR]
[TR]
[TD]B.2
[/TD]
[TD]2
[/TD]
[TD]2
[/TD]
[/TR]
[TR]
[TD]C
[/TD]
[TD]0
[/TD]
[TD]5
[/TD]
[/TR]
[TR]
[TD]C.1
[/TD]
[TD]3
[/TD]
[TD]3
[/TD]
[/TR]
[TR]
[TD]C.2
[/TD]
[TD]2
[/TD]
[TD]2
[/TD]
[/TR]
</tbody>[/TABLE]

I have my different strings in column A:A
And in column B:B i have a formula to find the string in column A in one text cell (Row 1:1).
But i want to organize by "headers"
The goal is obtain column C:C automatically, because i have several tables and they are not equal.

I was thinking in somethig like:

In cell B2: if indent of A2=0, sum cell B3:BXX, until the next indent of column A=0.

Does this make any sense?

I have already a VBA code to get the indent:
Code:
Function PROFEXIndentLevel(Cell As Range)
    'This function returns the indentation of a cell content
    
    Application.Volatile
    'With "Application.Volatile" you can make sure, that the function will be recalculated once the worksheet is recalculated
    'for example, when you press F9 (Windows) or press enter in a cell
    
    PROFEXIndentLevel = Cell.IndentLevel
    'Return the IndentLevel
    
End Function

Thanks,
Gonçalo
 

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.
What if you just use the below formula instead?

Code:
=IF(LEN(A2)=1,SUMPRODUCT(--(LEFT($A$2:$A$11,1)=LEFT($A2,1)),$B$2:$B$11),B2)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
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