Insert sum/subtotal formulae to sum values on a list

Son

Active Member
Joined
Mar 19, 2010
Messages
284
Hello, I have question about how to add rows with subotal and sum formulae in an excel list.
I have a database with names of employees working in various sections. Each Section has subsections who are run by managers and staff is working for them.

In the following example we have the following:
Column A shows the "position code", which is a code assigned to each "position". This code is handwritten, not automated. It is intended to show hierarchy of position.
Column B shows the "position" where each employee works.
Column C shows the count of staff that work in each "position". The actual staff is shown more clearly in column D, where you can see the numbers and the summing formulae.

For example rows 7, 8, 11, 12 all contain a summing formula or a subtotal formula.

In cell A3 I have the value "1", which is shown when I apply filters to the list. Because I use a lot of different filters in various columns (actually the whole list has more than 25 columns), I need the two different formulae in each summing row: ie to subtotal one and the sum one.

So far I have hardcoded each formula in each row. But I need to make this list more dynamic. I cannot use a pivot due to the various filters I need to apply and new data I show using vba.

Important thing to note is that I am using excel 2003 since I have not been able to upgrade my code as it presents many errors. The code also works well in excel 2007 but that's it.
Also, as you can see, my excel version uses " ; " instead of " , ".

I have over 50 modules of code and about 30 worksheets in each workbook. I also have about 15 workbooks, one for each branche of the company, but I need to create more workbooks for the new branches. The eample below is only a fraction of the whole list in the worksheet.

The content of Columns A and B is in a different worksheet and it is different for each branch. I use code to fill Column C (and the other 25+ columns, with different data. For example Column C shows the people working in the company regularly and Column D would normally show the temporary staff, and so on. As I said, the formulae are fixed and hardcoded by hand in each of the rows. My code only updates the cell that do not contain formulae.

I would be very grateful if you had any input on this problem and I'm looking forward to hearing your thoughts. Also, I'd be more than happy to answer any questions.

1ABCD
2
31
4
5
6POSITION CODEPOSITIONNUMBER OF STAFFFORMULA
71SECTION 12=IF($A$3<>1;SUBTOTAL(9;D8:D10);(D8))
81.0MANAGER'S 1 OFFICE2=IF($A$3<>1;SUBTOTAL(9;D9:D10);SUM(D9:D10))
91.0.1MANAGER 111
101.0.2ASSISTANT MANAGER11
112SECTION 2318=IF($A$3<>1;SUBTOTAL(9;D12:D113);(D12+D16+D18+D24+D30+D36+D59+D81+D86+D95+D102+D105+D109+D112))
122.0MANAGER'S 1 OFFICE3=IF($A$3<>1;SUBTOTAL(9;D13:D15);SUM(D13:D15))
132.0.1MANAGER 111
142.0.2ASSISTANT MANAGER 122
152.0.3ASSISTANT MANAGER 200
162.1MANAGER'S 2 OFFICE5=IF($A$3<>1;SUBTOTAL(9;D17);SUM(D17))
172.1.1MANAGER 255
182.2MANAGER'S 3 OFFICE40=IF($A$3<>1;SUBTOTAL(9;D19:D23);SUM(D19:D23))
192.2.1MANAGER 355
202.2.2ASSISTANT 11010
212.2.3ASSISTANT 255
222.2.4ASSISTANT 31010
232.2.5ASSISTANT 41010
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I forgot to say that I need that the positions are not fixed, there may be other positions inserted or deleted from this list. This is another reason that I would need this list to be dynamic. Any ideas???
 
Upvote 0
ok, so I'm reposting my question using xl2bb in the hope that it will make it more clear.

So, as I said above, I have a spreadsheet with employees according to their position in the company.
The data contains the code for each hiearchical position, the name of the position, and the number of employees in each hierarchical position.
The grey rows sum the number of employees for each section or department.
The problem is that the formulas in column C (counting the employees according to hierarchy level), are not automatic, I need to input specific ranges for each, by hand.
But, if I change the hierarchal structure, I need to rewrite the formulas by hand.

Is there a way that I can make the formulas automated, eg by using code? Or perhaps I could use summing by colour?
I cannot use a pivot because I need to use the data as a list, as I need to apply various filters.

Any ideas would be most appreciated!!! I'm looking forward to hearing your thouhts!



test.xls
ABC
1
2
31 = 1 means I have filters applied
4
5
6POSITION CODEPOSITION IN HIERARCHYCOUNT STAFF
71SECTION 12
81.0MANAGER'S 1 OFFICE2
91.0.1MANAGER 11
101.0.2ASSISTANT MANAGER1
112SECTION 2295
122.0MANAGER'S 1 OFFICE3
132.0.1MANAGER 11
142.0.2ASSISTANT MANAGER 12
152.0.3ASSISTANT MANAGER 20
162.1MANAGER'S 2 OFFICE5
172.1.1MANAGER 25
182.2MANAGER'S 3 OFFICE40
192.2.1MANAGER 35
202.2.2ASSISTANT 110
212.2.3ASSISTANT 25
222.2.4ASSISTANT 310
232.2.5ASSISTANT 410
242.3MANAGER'S 4 OFFICE45
252.3.1MANAGER 45
262.3.2ASSISTANT 110
272.3.3ASSISTANT 210
282.3.4ASSISTANT 310
292.3.5ASSISTANT 410
302.4MANAGER'S 5 OFFICE25
312.4.1MANAGER 55
322.4.2ASSISTANT 15
332.4.3ASSISTANT 25
342.4.4ASSISTANT 35
352.4.5ASSISTANT 45
362.5MANAGER'S 6 OFFICE78
372.5.1DAY PERSONNEL14
382.5.1.1MANAGER 61
392.5.1.2ASSISTANT 13
402.5.1.3ASSISTANT 26
412.5.1.4ASSISTANT 32
422.5.1.5ASSISTANT 40
432.5.1.6ASSISTANT 52
442.5.2SHIFT PERSONNEL64
452.5.2.1SHIFT MANAGER5
462.5.2.2ASSISTANT 15
472.5.2.3ASSISTANT 25
482.5.2.4ASSISTANT 35
492.5.2.5ASSISTANT 45
502.5.2.6ASSISTANT 515
512.5.2.7ASSISTANT 65
522.5.2.8ASSISTANT 75
532.5.2.9ASSISTANT 85
542.5.2.10ASSISTANT 95
552.5.2.11ASSISTANT 100
562.5.2.12ASSISTANT 110
572.5.2.13ASSISTANT 120
582.5.2.14ASSISTANT 134
592.6MANAGER'S 7 OFFICE48
602.6.1DAY PERSONNEL13
612.6.1.1MANAGER 71
622.6.1.2ASSISTANT 13
632.6.1.3ASSISTANT 29
642.6.1.4ASSISTANT 30
652.6.1.5ASSISTANT 40
662.6.2SHIFT PERSONNEL35
672.6.2.1SHIFT MANAGER5
682.6.2.2ASSISTANT 15
692.6.2.3ASSISTANT 25
702.6.2.4ASSISTANT 35
712.6.2.5ASSISTANT 45
722.6.2.6ASSISTANT 55
732.6.2.7ASSISTANT 60
742.6.2.8ASSISTANT 70
752.6.2.9ASSISTANT 85
762.6.2.10ASSISTANT 90
772.7MANAGER'S 8 OFFICE12
782.7.1MANAGER 81
792.7.2ASSISTANT 11
802.7.3ASSISTANT 25
812.7.4ASSISTANT 35
822.8MANAGER'S 9 OFFICE39
832.8.1MANAGER 94
842.8.2ASSISTANT 15
852.8.3ASSISTANT 25
862.8.4ASSISTANT 35
872.8.5ASSISTANT 45
882.8.6ASSISTANT 55
892.8.7ASSISTANT 65
902.8.8ASSISTANT 75
913SECTION 349
923.0MANAGER'S 1 OFFICE3
933.0.1MANAGER 11
943.0.2ASSISTANT 12
953.0.3ASSISTANT 20
963.1MANAGER'S 2 OFFICE6
973.1.1MANAGER 20
983.1.2ASSISTANT 12
993.1.3ASSISTANT 24
1003.1.4ASSISTANT 30
1013.1.5ASSISTANT 40
1023.2MANAGER'S 3 OFFICE2
1033.2.1MANAGER 31
1043.2.2ASSISTANT 11
1053.3MANAGER'S 4 OFFICE38
1063.3.1DAY PERSONNEL3
1073.3.1.1MANAGER 41
1083.3.1.2ASSISTANT 12
1093.3.1.3ASSISTANT 20
1103.3.2SHIFT PERSONNEL35
1113.3.2.1SHIFT MANAGER5
1123.3.2.2ASSISTANT 115
1133.3.2.3ASSISTANT 215
1143.4MANAGER'S 5 OFFICE0
1153.4.1MANAGER 50
1163.4.2ASSISTANT 10
test (staff)
Cell Formulas
RangeFormula
C7C7=IF($A$3<>1,SUBTOTAL(9,C8:C10),(C8))
C8,C114,C102C8=IF($A$3<>1,SUBTOTAL(9,C9:C10),SUM(C9:C10))
C11C11=IF($A$3<>1,SUBTOTAL(9,C12:C90),(C12+C16+C18+C24+C30+C36+C59+C77+C82))
C12,C110,C106,C92C12=IF($A$3<>1,SUBTOTAL(9,C13:C15),SUM(C13:C15))
C16C16=IF($A$3<>1,SUBTOTAL(9,C17),SUM(C17))
C18,C96,C60,C30,C24C18=IF($A$3<>1,SUBTOTAL(9,C19:C23),SUM(C19:C23))
C36C36=IF($A$3<>1,SUBTOTAL(9,C37:C58),(C37+C44))
C37C37=IF($A$3<>1,SUBTOTAL(9,C38:C43),SUM(C38:C43))
C44C44=IF($A$3<>1,SUBTOTAL(9,C45:C58),SUM(C45:C58))
C59C59=IF($A$3<>1,SUBTOTAL(9,C60:C76),(C60+C66))
C66C66=IF($A$3<>1,SUBTOTAL(9,C67:C76),SUM(C67:C76))
C77C77=IF($A$3<>1,SUBTOTAL(9,C78:C81),SUM(C78:C81))
C82C82=IF($A$3<>1,SUBTOTAL(9,C83:C90),SUM(C83:C90))
C91C91=IF($A$3<>1,SUBTOTAL(9,C92:C116),(C92+C96+C102+C105+C114))
C105C105=IF($A$3<>1,SUBTOTAL(9,C106:C113),(C106+C110))
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,307
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