Insert Formulas in list of data

kalbercht

New Member
Joined
Sep 16, 2009
Messages
6
Hi - I have a list of records summarizing individuals by cost center (there's also other fields of data but these are the 2 main ones that I'm concerned about).

I need to be able to insert a row at each change in cost center and then insert a formula to count the number of individuals within that cost center. (So all of the rows above - up to the point of a different cost center).



I need to be able to physically insert a formula and the the count value as data may change. The formulas need to be able to recalculate the count of inviduals.


The data looks like this:

Doe Jane CstCtr1
Evans Joe CstCtr1
Jones Kris CstCtr1
Abrams Mack CstCtr2
Evans Mary CstCtr2


I need it to look like this:



Doe Jane CstCtr1
Evans Joe CstCtr1
Jones Kris CstCtr1

Count 3 <---this needs to be a formula


Abrams Mack CstCtr2
Evans Mary CstCtr2

Count 2 <---this needs to be a formula



Many thanks.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
If your only counting cstctrl
=COUNTIF(B3:B200,"cstctrl1")
=COUNTIF(B3:B200,"cstctrl2")
 
Upvote 0
Welcome to the MrExcel board!

Have a look at Excel's built-in Subtotal feature (I assume your columns have headings). It will insert the rows and the formulas for you. If you need more detailed help with *how* to do it, post back and tell us what Excel version you are using.
 
Upvote 0
Thanks for the replies. I'm on Excel 2007. I need to use macros to insert the formulas and not the subtotal function because I will need to adjust it to insert additional subtotals.


I'm imagining that somehow I need to figure out the range of the records within a cost center, determine the last row and insert the formula, and then determine the range of the next cost center, etc.... until all cost centers are reviewed.


I can probably do this but it would take me some time.

Thanks again!
 
Upvote 0
Thanks for the replies. I'm on Excel 2007. I need to use macros to insert the formulas and not the subtotal function because I will need to adjust it to insert additional subtotals.
If the suggestion below does not solve your problem, then expanding on what you mean by this may help us to understand.



I'm imagining that somehow I need to figure out the range of the records within a cost center, determine the last row and insert the formula, and then determine the range of the next cost center, etc.... until all cost centers are reviewed.
You shouldn't need to do this - the Subtotal feature does it for you.

Assuming the data has headings and starts in A1 like this:

Excel Workbook
AB
1NameCost Centre
2Doe JaneCstCtr1
3Evans JoeCstCtr1
4Jones KrisCstCtr1
5Abrams MackCstCtr2
6Evans MaryCstCtr2
Sheet1



Then run this macro (or do it manually)

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> Cost_Centres()<br>    Range("A1").Subtotal GroupBy:=2, Function:=xlCount, TotalList:=Array(2), _<br>        Replace:=True, PageBreaks:=False, SummaryBelowData:=<SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>


This is the result:

Excel Workbook
AB
1NameCost Centre
2Doe JaneCstCtr1
3Evans JoeCstCtr1
4Jones KrisCstCtr1
5CstCtr1 Count3
6Abrams MackCstCtr2
7Evans MaryCstCtr2
8CstCtr2 Count2
9Grand Count5
Sheet1
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,134
Members
452,890
Latest member
Nikhil Ramesh

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