View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
joel joel is offline
external usenet poster
 
Posts: 9,101
Default subtotal by week with duplicate dates?

The macro below will work. It is not 100% bullet proof. It tests if a new
week occurs by check the day of the week. If the day of the week of the
nextt line is less than the day of the week of the present line it performs a
subtotal

for eample
row 10 is Friday
row 11 is Monday

the code says friday is the end of the week. this doesn't work in every
case, it only works if you have data every day. I can make the macro better
if you need it changed. I took the simple approach first. there is a
function WEEKNUM but it doesn't work on my PC.



StartRow = 2 'start after header row
RowCount = StartRow
OldDayofWeek = Weekday(Range("A2"))
FirstRow = StartRow
Do While Range("A" & RowCount) < ""
If IsDate(Range("A" & (RowCount + 1))) Then
NewDayofWeek = Weekday(Range("A" & (RowCount + 1)))
Else
NewDayofWeek = 0
End If
If NewDayofWeek < OldDayofWeek Then
Range("C" & RowCount).Formula = _
"=Sum(B" & FirstRow & ":B" & RowCount & ")"
OldDayofWeek = NewDayofWeek
FirstRow = RowCount + 1
End If
RowCount = RowCount + 1
Loop


"Beth" wrote:

I'm trying to subtotal data by calendar week with duplicate and
non-consecutive dates - please help? Column A represents an invoice date,
Column B represents the qty shipped. I need the total qty shipped per week?

Date QTY
1/4/06 864
1/4/06 192
1/5/06 144
1/5/06 192
1/5/06 48
1/5/06 528
1/6/06 48
1/9/06 384
1/9/06 240
1/10/06 1,008.00
1/10/06 480
1/10/06 768
1/10/06 720
1/10/06 240

Thanks!