VBA Subtotal(9,"range") based on indent

jocker_boy

Board Regular
Joined
Feb 5, 2015
Messages
83
Hello,

I would like to use some macro to populate cells with the formula subtotal(9,"range"), being the range dinamic, based on the lenght of the cell.
For example:

indentlenghtFormula
F.91.04
7​
150
F.91.04.01
10​
60
F.91.04.01.07
13​
30
F.91.04.01.07.01
16​
10​
F.91.04.01.07.04
16​
20​
F.91.04.01.12
13​
30
F.91.04.01.12.07
16​
30​
F.91.04.80
10​
90
F.91.04.80.01
13​
40​
F.91.04.80.02
13​
50​
F.91.05
7​
260
F.91.05.02
10​
260
F.91.05.02.01
13​
260
F.91.05.02.01.01
16​
210
F.91.05.02.01.01.80
19​
210
F.91.05.02.01.01.80.01
22​
60​
F.91.05.02.01.01.80.02
22​
70​
F.91.05.02.01.01.80.03
22​
80​
F.91.05.02.01.02
16​
10​
F.91.05.02.01.03
16​
10​
F.91.05.02.01.04
16​
10​
F.91.05.02.01.05
16​
10​
F.91.05.02.01.07
16​
10​

In this table, i have in column A:A my indent value.
I calculate in column B:B the lenght of each cell A:A
My goal is to populate in column C:C, for each cell the formula: =subtotal(9;range), where the range is limited by the lenght number. It should only create the formula if the lenght of the next cell if superior, if it is equal it should be blank.
In this example, all the blues values are obtain in the formula =subtotal(9;range), the range should check the lenght of the column B:B, start the next cell and finish until the lenght is superior.

It is hard to explain.
Sorry,

Gonçalo
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hello,

I will try to explain another way.

In column A i have my indent value.
In column B e calculate the lenght of each cell of column A
The column C is blank and i want to populate each cell with 2 possibilities.
It have to check the value on column B, and compare to the row below.
If the value of the row below is equal or inferior, it must be "blank", if not, will create a formula =subtotal(9,range), the range will start the row below and go until find a lenght equal or inferior.

ABC (lenght)D (formula with macro)
121=subtotal(9,B2:B7)
22.13=subtotal(9,B3:B4)
32.1.15
42.1.25
52.23=subtotal(9,B6:B6)
62.2.15
72.33

Many thanks,
Gonçalo
 
Upvote 0
Hello,

I will try to explain another way.

In column A i have my indent value.
In column B e calculate the lenght of each cell of column A
The column C is blank and i want to populate each cell with 2 possibilities.
It have to check the value on column B, and compare to the row below.
If the value of the row below is equal or inferior, it must be "blank", if not, will create a formula =subtotal(9,range), the range will start the row below and go until find a lenght equal or inferior.

ABC (lenght)D (formula with macro)
121=subtotal(9,B2:B7)
22.13=subtotal(9,B3:B4)
32.1.15
42.1.25
52.23=subtotal(9,B6:B6)
62.2.15
72.33

Many thanks,
Gonçalo
Hello,

Anyone can help?
I have more than 1000 rows and i have to populate several with subtotal formula.

Thanks,
Gonçalo
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,597
Members
449,038
Latest member
Arbind kumar

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