VBa code to subtotal by week ending date and monthly total

rjrsn

New Member
Joined
Feb 16, 2005
Messages
25
Hello, Help needed in a report. The data is listed in columns as indicated below. I need to generate a report showing an end of week subtotal ending on each Thursday at close of business. The fields that I need to generate by VBA are listed below the data. I need VBA to make each column and compile all data listed from Friday to the following Thursday and would be listed as week ending. The second week I need the same calculation based only on the second week, and then the 3rd and the 4th and/or 5th if it occurs. Once the weekly totals are calculated it goes into the weekly rows. Each week that ends in Thursday will have it's own total with the final row giving the monthly total. Can someone help me with the particular code to do this? Thanks for the anticipated help and feel free to ask any questions and I am able to privately email the particular document as necessary. Bob


LOCATION DATE "TRACE ID
NUMBER
(MMYY-NUMBER)" "BEGIN
TIME
(PULL DOWN)" "END
TIME
(PULL DOWN)" HOURS OFFICER "HMV
SPEED" HMV OTHER NHMV PARKING VW SPEED VW OTHER ARRESTS CRASHES CARS TOWED TOTAL
these are the fields where data is entered:

Subtotal lines are displayed as indicated below:

Week Ending HOURS "HMV
SPEED" HMV OTHER NHMV PARKING VW SPEED VW OTHER ARRESTS CRASHES CARS TOWED TOTAL
Thursday, November 9, 2017
Thursday, November 16, 2017
Thursday, November 23, 2017
Thursday, November 30, 2017
Totals for Month of (pulled from the week ending)
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
can you put it in a spreadsheet layout as it is unclear ie is location .. date... traceidnumber...begintime...endtime...hoursofficer....hmvspeed....etc etc
 
Upvote 0
Hello, Help needed in a report. The data is listed in columns as indicated below. I need to generate a report showing an end of week subtotal ending on each Thursday at close of business. The fields that I need to generate by VBA are listed below the data. I need VBA to make each column and compile all data listed from Friday to the following Thursday and would be listed as week ending. The second week I need the same calculation based only on the second week, and then the 3rd and the 4th and/or 5th if it occurs. Once the weekly totals are calculated it goes into the weekly rows. Each week that ends in Thursday will have it's own total with the final row giving the monthly total. Can someone help me with the particular code to do this? Thanks for the anticipated help and feel free to ask any questions and I am able to privately email the particular document as necessary. Bob


LOCATION DATE "TRACE ID
NUMBER
(MMYY-NUMBER)" "BEGIN
TIME
(PULL DOWN)" "END
TIME
(PULL DOWN)" HOURS OFFICER "HMV
SPEED" HMV OTHER NHMV PARKING VW SPEED VW OTHER ARRESTS CRASHES CARS TOWED TOTAL
these are the fields where data is entered:

Subtotal lines are displayed as indicated below:

Week Ending HOURS "HMV
SPEED" HMV OTHER NHMV PARKING VW SPEED VW OTHER ARRESTS CRASHES CARS TOWED TOTAL
Thursday, November 9, 2017
Thursday, November 16, 2017
Thursday, November 23, 2017
Thursday, November 30, 2017
Totals for Month of (pulled from the week ending)

Came up with a simpler way I think. I have repeating data in rows 1 through 6 consisting of letterhead and a jpg picture.
A7-LOCATION
B7-DATE
C7-"TRACE ID NUMBER (MMYY-NUMBER)"
D7- "BEGIN TIME (PULL DOWN)"
E7-"END TIME (PULL DOWN)"
F7-HOURS(calculated field)
G7-OFFICER
H7-"HMV SPEED"
I7-HMV OTHER
J7-NHMV
K7-PARKING
L7-VW SPEED
M7-VW OTHER
N7-ARRESTS
O7-CRASHES
P7-CARS TOWED
Q7-TOTAL --Calculated formula SUM
Data is entered one event per row continuing down the worksheet.

In cells AB7 THROUGH AT13 is a range of cells showing weekly totals. 1st step of macro is to copy this range and insert it into cell A7 and also move the existing data down to row 14. So it should be insert copied data into the row and not erase anything. I say this because I don't want existing data overwritten just moved down.
Ok we have the new range inserted and all data is intact. Once this range is copied and inserted, cell A8 requires a date. I would like the macro to search the data in column B, starting at row 14 for the first Friday in the month of the dates in column B. example: date is shown as 11/14/2017. The macro reads the date as November and puts the date of the first friday in the month of November into cell A8.The macro should use this date to do a search of column B and search for any date from that Friday back to the previous Saturday Friday - 6 . Then search for all of these dates and sort chronologically in column B.
The macro should do a subtotal (weekly totals) on columns C, (this column has multiple numbers in it and I need a count of all non-blank cells during this time), F, and H through P, with a total of this row in column Q of the inserted range in row 8. Now the Macro inserts a blank line after the first week of data in the data.
the next Row 9, the macro would repeat itself but with the next week and data put into for the second weeks subtotals and again insert a blank line at the end of the second weeks data.
I couldn't upload a picture of what Im talking about, sorry. I hope this isn't too big of a job but I'm at a loss on how to make this work. It is for a traffic unit in a police department where I am a stat keeper. Any questions please ask and I hope I can be helped. thanks in advance.
 
Upvote 0
col Q
london01/10/20171017-100110:3513:5903:24Dibble73other1something1no66vwother1201
london01/10/20171017-100206:1409:4403:30Jones84other2something2no64vwother2111
is this the data
put in any altrerations
say what the total column actually totals
then I will add weekly and monthly totals

<colgroup><col><col><col span="7"><col><col span="8"></colgroup><tbody>
</tbody>
 
Upvote 0
Hours in column is calculated and formatted as: [h]:mm;@ in the choices. I must ask that this would be the proper formatting for the hours to calculate and post such as 47:45 which would be 47 hours and 45 minutes. Just to make sure...

All data from H7 over to the right are whole numbers. They are listing the total number of violations and not the actual offense.
Q7 sums from H over to P and is formatted as a whole number.

Thanks Bob
 
Upvote 0
col Q
london29/09/20170917-100104:3506:5902:24name1735791113468136row 7
london30/09/20170917-100204:5407:2402:30name274891113156810154
london01/10/20171017-100305:1307:4902:36name375111113151781012172
london02/10/20171017-100405:3208:1402:42name4761413151719101214190
london03/10/20171017-100505:5108:3902:48name5771715171921121416208
london04/10/20171017-100606:1009:0402:54name6782017192123141618226
london05/10/20171017-100706:2909:2903:00name7792319212325161820244
london06/10/20171017-100806:4809:5403:06name8802621232527182022262
london07/10/20171017-100907:0710:1903:12name1812923252729202224280
london08/10/20171017-101007:2610:4403:18name2823225272931222426298
london09/10/20171017-101107:4511:0903:24name3833527293133242628316
london10/10/20171017-101208:0411:3403:30name4843829313335262830334
london11/10/20171017-101308:2311:5903:36name5854131333537283032352
london12/10/20171017-101408:4212:2403:42name6864433353739303234370
london13/10/20171017-101509:0112:4903:48name7874735373941323436388
london14/10/20171017-101609:2013:1403:54name8885037394143343638406
london15/10/20171017-101709:3913:3904:00name1895339414345363840424
london16/10/20171017-101809:5814:0404:06name2905641434547384042442
london17/10/20171017-101910:1714:2904:12name3915943454749404244460
london18/10/20171017-102010:3614:5404:18name4926245474951424446478
london19/10/20171017-102110:5515:1904:24name5936547495153444648496
london20/10/20171017-102211:1415:4404:30name6946849515355464850514
london21/10/20171017-102311:3316:0904:36name7957151535557485052532
london22/10/20171017-102411:5216:3404:42name8967453555759505254550
london23/10/20171017-102512:1116:5904:48name1977755575961525456568
london24/10/20171017-102612:3017:2404:54name2988057596163545658586
london25/10/20171017-102712:4917:4905:00name3998359616365565860604
london26/10/20171017-102813:0818:1405:06name41008661636567586062622
london27/10/20171017-102913:2718:3905:12name51018963656769606264640
london28/10/20171017-103013:4619:0405:18name61029265676971626466658
london29/10/20171017-103114:0519:2905:24name71039567697173646668676
london30/10/20171017-103214:2419:5405:30name81049869717375666870694
london31/10/20171017-103314:4320:1905:36name110510171737577687072712
london01/11/20171117-103415:0220:4405:42name210610473757779707274730
london02/11/20171117-103515:2121:0905:48name310710775777981727476748
london03/11/20171117-103615:4021:3405:54name410811077798183747678766
london04/11/20171117-103715:5921:5906:00name510911379818385767880784
london05/11/20171117-103816:1822:2406:06name611011681838587788082802
london06/11/20171117-103916:3722:4906:12name711111983858789808284820
london07/11/20171117-104016:5623:1406:18name811212285878991828486838
FRIDAYScol Q
29/09/20171330one step at a time
06/10/20172212
13/10/20173094by listing the dates of the Fridays easy to total for weeks ending on Thursdays
20/10/20173976
27/10/20174858
03/11/20174010
10/11/20170
17/11/20170
24/11/20170

<colgroup><col><col><col span="7"><col><col span="8"></colgroup><tbody>
</tbody>
 
Upvote 0
This is looking great. Have the totals in column Q but when compiling that also need totals for the weekly stats for columns F, H through Q and will be inserted at the beginning of the data with the date listed as the Friday's date. I think I misspoke and the subtotals of the data by the week should end on the friday entered to search for and go back to the previous Saturday. The data week is always Saturday through Friday. I realize your sorted and subtotaled data can be moved to the location that I will ultimately assign it when I put a specific template into a specific set of cells.
When the totals/subtotals are calculated can a blank row be inserted into the data to seperate one week from the next and as each week is calculated a blank row would be inserted? When inserting that blank row can we color it a medium grey where not information would be there?

This is looking so great, thank you.
 
Upvote 0
col Qhelper
london30/09/20170917-100104:3506:5902:24name17357911134681361
london30/09/2017 04:5407:2402:30name2748911131568101540
london01/10/20171017-100305:1307:4902:36name3751111131517810121721
london02/10/2017 05:3208:1402:42name47614131517191012141900
london03/10/20171017-100505:5108:3902:48name57717151719211214162081
london04/10/20171017-100606:1009:0402:54name67820171921231416182261
london05/10/20171017-100706:2909:2903:00name77923192123251618202441
london06/10/20171017-100806:4809:5403:06name88026212325271820222621
london07/10/20171017-100907:0710:1903:12name18129232527292022242801
london08/10/20171017-101007:2610:4403:18name28232252729312224262981
london09/10/20171017-101107:4511:0903:24name38335272931332426283161
london10/10/20171017-101208:0411:3403:30name48438293133352628303341
london11/10/20171017-101308:2311:5903:36name58541313335372830323521
london12/10/20171017-101408:4212:2403:42name68644333537393032343701
london13/10/20171017-101509:0112:4903:48name78747353739413234363881
london14/10/20171017-101609:2013:1403:54name88850373941433436384061
london15/10/20171017-101709:3913:3904:00name18953394143453638404241
london16/10/20171017-101809:5814:0404:06name29056414345473840424421
london17/10/20171017-101910:1714:2904:12name39159434547494042444601
london18/10/20171017-102010:3614:5404:18name49262454749514244464781
london19/10/20171017-102110:5515:1904:24name59365474951534446484961
london20/10/20171017-102211:1415:4404:30name69468495153554648505141
london21/10/20171017-102311:3316:0904:36name79571515355574850525321
london22/10/20171017-102411:5216:3404:42name89674535557595052545501
london23/10/20171017-102512:1116:5904:48name19777555759615254565681
london24/10/20171017-102612:3017:2404:54name29880575961635456585861
london25/10/20171017-102712:4917:4905:00name39983596163655658606041
london26/10/20171017-102813:0818:1405:06name410086616365675860626221
london27/10/20171017-102913:2718:3905:12name510189636567696062646401
london28/10/20171017-103013:4619:0405:18name610292656769716264666581
london29/10/20171017-103114:0519:2905:24name710395676971736466686761
london30/10/20171017-103214:2419:5405:30name810498697173756668706941
london31/10/20171017-103314:4320:1905:36name1105101717375776870727121
london01/11/20171117-103415:0220:4405:42name2106104737577797072747301
london02/11/20171117-103515:2121:0905:48name3107107757779817274767481
london03/11/20171117-103615:4021:3405:54name4108110777981837476787661
london04/11/20171117-103715:5921:5906:00name5109113798183857678807841
london05/11/20171117-103816:1822:2406:06name6110116818385877880828021
london06/11/20171117-103916:3722:4906:12name7111119838587898082848201
london07/11/20171117-104016:5623:1406:18name8112122858789918284868381
SATURDAYScol Qcol Fcol Hcol Icol Jcol Kcol Lcol Mcol Ncol Ocol Pcol C count<>""
30/09/2017159222:00612124112128144160881041206
07/10/2017233800:305882662032172312451821962107
14/10/2017322005:246374133013153293432802943087
21/10/2017410210:186865603994134274413783924067
28/10/2017498415:127357074975115255394764905047
04/11/2017324400:364424703283363443523163243324
11/11/2017000:000000000000
18/11/2017000:000000000000
25/11/2017000:000000000000
I am working on col F as when hours total over 24 they reset to zero
week is now sat to Friday
for testing purposes I deleted a couple of col C id's

<colgroup><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col span="5"></colgroup><tbody>
</tbody>
 
Upvote 0
the data can be in any order so not sure how and why you want rows moved and spaces inserted..........
 
Upvote 0
This is looking so great. The hours used to reset for me too but when I formated the time to be [h]:mm:ss;@ it seemed to correct it. I did eliminate the "ss" part because I didn't need seconds.

When the report is presented to my superior's I will provide them with the weekly summary which will be the pasted part of the form. All these calculations occur there. The addition of a blank line after each week was subtotaled helps clarify the division between each week and was something the Major wanted me to do. If doable great if not no prob. To address your question about moving the subtotals into the rows in looking back at it I don't. I will keep the subtotals always displayed where they were going to be pasted. So the rows that I was going to insert will already have the formatting inserted and no need to copy from another part of the sheet. I didn't think that one clearly enough. The blank column will be helpful to look at the weeks for specific data and see where it ends. I will make a new note to you confirming the exact locations and such that each of the subtotaled data goes into. I'll post soon. thanks so much
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,858
Members
449,051
Latest member
excelquestion515

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