Automate formulas in a list using code

Status
Not open for further replies.

Son

Active Member
Joined
Mar 19, 2010
Messages
284
Hello, 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.
I have already posted this in another thread, but I repost using xl2bb since I believe this would be more helpful.

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))
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Status
Not open for further replies.

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

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