Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Function to subtotal by employee and also by month for each employ

There are 50 employees and have a variable number of records for each
employee. I can easily subtotal by each employee however I need also to
subtotal each month for each employee. All works well until I hit one of
those employees whose 1st month total is the same as the previous employees
last month total. I have figured out how to group each employees records
together but cannot figure out how to subtotal the month within each group.
Any help is appreciated. As below, when I hit one of the records in question
my monthly totals now show up below the grand totals, then throwing the
remainder of the spreadsheet off also.

5/23/2009 5 Jane Doe1 282160
5/30/2009 5 Jane Doe1 259456
5 Total 541616
6/6/2009 6 Jane Doe1 251424
6 Total 251424
Jane Doe 1 Total 793040
5/16/2009 5 Jon Doe 14636
5/23/2009 5 Jon Doe 103154
Jon Doe Total 117790
5 Total 117790
5/16/2009 5 Jane Doe 2 104204
Jane Doe 2 Total 104204
5 Total 104204

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Function to subtotal by employee and also by month for each employ

Try this. I've done this type of problem before. I used inserted worksheet
formulas into the worksheet to perform the totals.

Sub GetTotals()

'sort data
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
Rows("1:" & Lastrow).Sort _
header:=xlNo, _
key1:=Range("C1"), _
order1:=xlAscending, _
key2:=Range("A1"), _
order2:=xlAscending

RowCount = 1
StartEmployee = RowCount
StartMonth = RowCount

Do While Range("A" & RowCount) < ""
'check if month or emplyee doesn't match
If Month(Range("A" & RowCount)) < _
Month(Range("A" & (RowCount + 1))) Or _
Range("C" & RowCount) < Range("C" & (RowCount + 1)) Then

Rows(RowCount + 1).Insert
Range("A" & (RowCount + 1)) = "Monthly Total"
Range("B" & (RowCount + 1)).Formula = _
"=Sum(B" & StartMonth & ":B" & RowCount & ")"
Range("D" & (RowCount + 1)).Formula = _
"=Sum(D" & StartMonth & ":D" & RowCount & ")"

'check if employee doesn't match
If Range("C" & RowCount) < _
Range("C" & (RowCount + 2)) Then

Rows(RowCount + 2).Insert
Range("A" & (RowCount + 2)) = "Employee Total"
Range("B" & (RowCount + 2)).Formula = _
"=Sumproduct(" & _
"--(A" & StartEmployee & ":A" & RowCount & "<""Monthly
Total"")," & _
"B" & StartEmployee & ":B" & RowCount & ")"
Range("D" & (RowCount + 2)).Formula = _
"=Sumproduct(" & _
"--(A" & StartEmployee & ":A" & RowCount & "<""Monthly
Total"")," & _
"D" & StartEmployee & ":D" & RowCount & ")"

RowCount = RowCount + 3
StartMonth = RowCount
StartEmployee = RowCount
Else
RowCount = RowCount + 2
StartMonth = RowCount
End If
Else
RowCount = RowCount + 1
End If

Loop


End Sub





"jeremiah" wrote:

There are 50 employees and have a variable number of records for each
employee. I can easily subtotal by each employee however I need also to
subtotal each month for each employee. All works well until I hit one of
those employees whose 1st month total is the same as the previous employees
last month total. I have figured out how to group each employees records
together but cannot figure out how to subtotal the month within each group.
Any help is appreciated. As below, when I hit one of the records in question
my monthly totals now show up below the grand totals, then throwing the
remainder of the spreadsheet off also.

5/23/2009 5 Jane Doe1 282160
5/30/2009 5 Jane Doe1 259456
5 Total 541616
6/6/2009 6 Jane Doe1 251424
6 Total 251424
Jane Doe 1 Total 793040
5/16/2009 5 Jon Doe 14636
5/23/2009 5 Jon Doe 103154
Jon Doe Total 117790
5 Total 117790
5/16/2009 5 Jane Doe 2 104204
Jane Doe 2 Total 104204
5 Total 104204

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 806
Default Function to subtotal by employee and also by month for eachemploy

Hello,

Please have a look at my UDF Sfreq:
http://www.sulprobil.com/html/sfreq.html

Regards,
Bernd
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Function to subtotal by employee and also by month for each em

Thanks so much, I do have Joel's solution working but will figure out which
one works best for my needs. You guys are amazing!

"Bernd P" wrote:

Hello,

Please have a look at my UDF Sfreq:
http://www.sulprobil.com/html/sfreq.html

Regards,
Bernd

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lookup Function? Employee Number with Employee Name Lance Hebert[_2_] Excel Worksheet Functions 1 March 9th 10 05:25 PM
How many days in a row does an employee work within a 2 month peri LEG Excel Discussion (Misc queries) 2 December 16th 09 08:47 PM
Excel automation: how to employ Find function? fred Excel Programming 9 June 11th 09 09:30 PM
Subtotal by Month and supplier d7 Excel Worksheet Functions 2 February 18th 09 08:44 AM
Counting the days worked in a month by employee Curtis Excel Worksheet Functions 0 November 8th 05 05:15 PM


All times are GMT +1. The time now is 05:31 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"