VBA Question- Demand Analysis...How can I count activity by time of day?

WonkaCEO

New Member
Joined
Sep 3, 2015
Messages
4
Excel 2010
ABC

<tbody>
[TD="align: center"]1[/TD]
[TD="bgcolor: #000000, align: center"]Customer Number[/TD]
[TD="bgcolor: #000000, align: center"]In Date-Time[/TD]
[TD="bgcolor: #000000, align: center"]Out Date-Time[/TD]

[TD="align: center"]2[/TD]
[TD="align: center"]1[/TD]
[TD="align: right"]9/3/2015 15:00[/TD]
[TD="align: right"]9/4/2015 15:36[/TD]

[TD="align: center"]3[/TD]
[TD="align: center"]2[/TD]
[TD="align: right"]9/3/2015 15:20[/TD]
[TD="align: right"]9/4/2015 9:45[/TD]

[TD="align: center"]4[/TD]
[TD="align: center"]3[/TD]
[TD="align: right"]9/5/2015 12:15[/TD]
[TD="align: right"]9/7/2015 15:59[/TD]

[TD="align: center"]5[/TD]
[TD="align: center"]4[/TD]
[TD="align: right"]9/5/2015 15:00[/TD]
[TD="align: right"]9/6/2015 15:03[/TD]

[TD="align: center"]6[/TD]
[TD="align: center"]5[/TD]
[TD="align: right"]9/7/2015 8:00[/TD]
[TD="align: right"]9/8/2015 18:09[/TD]

[TD="align: center"]7[/TD]
[TD="align: center"]6[/TD]
[TD="align: right"]9/7/2015 13:00[/TD]
[TD="align: right"]9/9/2015 13:36[/TD]

[TD="align: center"]8[/TD]
[TD="align: center"]7[/TD]
[TD="align: right"]9/10/2015 11:00[/TD]
[TD="align: right"]9/13/2015 16:52[/TD]

[TD="align: center"]9[/TD]
[TD="align: center"]8[/TD]
[TD="align: right"]9/10/2015 10:23[/TD]
[TD="align: right"]9/11/2015 7:44[/TD]

[TD="align: center"]10[/TD]
[TD="align: center"]9[/TD]
[TD="align: right"]9/11/2015 7:00[/TD]
[TD="align: right"]9/12/2015 10:36[/TD]

[TD="align: center"]11[/TD]
[TD="align: center"]10[/TD]
[TD="align: right"]9/11/2015 8:00[/TD]
[TD="align: right"]9/11/2015 13:52[/TD]

</tbody>
Data

My data lists a series of customers leaving their cars for service. I'd like to develop VBA code that will count the number of cars that are present during each hour of the day.

I'm looking to create output that lists each hours of the day and the number of cars that were present during each hour. Any help would be greatly appreciated.

Here's a sample of the output:

Excel 2010
AB

<colgroup><col style="width: 25pxpx"><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="bgcolor: #000000, align: center"]Hour of Day[/TD]
[TD="bgcolor: #000000, align: center"]Count of Customers[/TD]

[TD="align: center"]2[/TD]
[TD="align: center"]00[/TD]
[TD="align: right"][/TD]

[TD="align: center"]3[/TD]
[TD="align: center"]01[/TD]
[TD="align: right"][/TD]

[TD="align: center"]4[/TD]
[TD="align: center"]02[/TD]
[TD="align: right"][/TD]

[TD="align: center"]5[/TD]
[TD="align: center"]03[/TD]
[TD="align: right"][/TD]

[TD="align: center"]6[/TD]
[TD="align: center"]04[/TD]
[TD="align: right"][/TD]

[TD="align: center"]7[/TD]
[TD="align: center"]05[/TD]
[TD="align: right"][/TD]

[TD="align: center"]8[/TD]
[TD="align: center"]06[/TD]
[TD="align: right"][/TD]

[TD="align: center"]9[/TD]
[TD="align: center"]07[/TD]
[TD="align: right"][/TD]

[TD="align: center"]10[/TD]
[TD="align: center"]08[/TD]
[TD="align: right"][/TD]

[TD="align: center"]11[/TD]
[TD="align: center"]09[/TD]
[TD="align: right"][/TD]

[TD="align: center"]12[/TD]
[TD="align: center"]10[/TD]
[TD="align: right"][/TD]

[TD="align: center"]13[/TD]
[TD="align: center"]11[/TD]
[TD="align: right"][/TD]

[TD="align: center"]14[/TD]
[TD="align: center"]12[/TD]
[TD="align: right"][/TD]

[TD="align: center"]15[/TD]
[TD="align: center"]13[/TD]
[TD="align: right"][/TD]

[TD="align: center"]16[/TD]
[TD="align: center"]14[/TD]
[TD="align: right"][/TD]

[TD="align: center"]17[/TD]
[TD="align: center"]15[/TD]
[TD="align: right"][/TD]

[TD="align: center"]18[/TD]
[TD="align: center"]16[/TD]
[TD="align: right"][/TD]

[TD="align: center"]19[/TD]
[TD="align: center"]17[/TD]
[TD="align: right"][/TD]

[TD="align: center"]20[/TD]
[TD="align: center"]18[/TD]
[TD="align: right"][/TD]

[TD="align: center"]21[/TD]
[TD="align: center"]19[/TD]
[TD="align: right"][/TD]

[TD="align: center"]22[/TD]
[TD="align: center"]20[/TD]
[TD="align: right"][/TD]

[TD="align: center"]23[/TD]
[TD="align: center"]21[/TD]
[TD="align: right"][/TD]

[TD="align: center"]24[/TD]
[TD="align: center"]22[/TD]
[TD="align: right"][/TD]

[TD="align: center"]25[/TD]
[TD="align: center"]23[/TD]
[TD="align: right"][/TD]

</tbody>
Output
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Are you sure the list should be 0 - 24? Should you not also have to add the date?

[TABLE="width: 800"]
<tbody>[TR]
[TD]
[/TD]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Hour of day:[/TD]
[TD]Count of customers:[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]9/3/2015 0:00[/TD]
[TD]=COUNTIFS('DATA'!B:B;"<="&'OUTPUT'!A2;'DATA'!C:C;">="&'OUTPUT'!A2)[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]=$A2+1/24[/TD]
[TD]=COUNTIFS('DATA'!B:B;"<="&'OUTPUT'!A3;'DATA'!C:C;">="&'OUTPUT'!A3)[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]=$A3+1/24[/TD]
[TD]=COUNTIFS('DATA'!B:B;"<="&'OUTPUT'!A4;'DATA'!C:C;">="&'OUTPUT'!A4)[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]=$A4+1/24[/TD]
[TD]=COUNTIFS('DATA'!B:B;"<="&'OUTPUT'!A5;'DATA'!C:C;">="&'OUTPUT'!A5)[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]=$A5+1/24[/TD]
[TD]=COUNTIFS('DATA'!B:B;"<="&'OUTPUT'!A6;'DATA'!C:C;">="&'OUTPUT'!A6)[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]etc[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]



Because list including date would grow very large you might want to consider creating a field in which you type the date, and that the table is updated based on that field. For instance in below table the date would be entered in B1:

[TABLE="width: 800"]
<tbody>[TR]
[TD]
[/TD]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Input field for date[/TD]
[TD]9/3/2015[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Hour of day:[/TD]
[TD]Count of customers:[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]=$B$1+0/24[/TD]
[TD]=COUNTIFS('DATA'!B:B;"<="&'OUTPUT'!A4;'DATA'!C:C;">="&'OUTPUT'!A4)[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]=$A4+1/24[/TD]
[TD]=COUNTIFS('DATA'!B:B;"<="&'OUTPUT'!A5;'DATA'!C:C;">="&'OUTPUT'!A5)[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]=$A5+1/24[/TD]
[TD]=COUNTIFS('DATA'!B:B;"<="&'OUTPUT'!A6;'DATA'!C:C;">="&'OUTPUT'!A6)[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]=$A6+1/24[/TD]
[TD]=COUNTIFS('DATA'!B:B;"<="&'OUTPUT'!A7;'DATA'!C:C;">="&'OUTPUT'!A7)[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]=$A7+1/24[/TD]
[TD]=COUNTIFS('DATA'!B:B;"<="&'OUTPUT'!A8;'DATA'!C:C;">="&'OUTPUT'!A8)[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]etc[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]




Edited to add row numbers and column headers to the tables
 
Last edited:
Upvote 0
Peter,

I am ultimately looking to calculate the average number of cars in each hour per day. My intent of the output was to add the number of occurrences in each hour and divide by the total number of days in the study. Currently, I am looking to do this for a period of 1 year.

Thanks again for the help.
 
Upvote 0
Ok, in that case I would need three helper columns on the source data. I would not be susprised if someone with more excel skills knows how to do it without helper columns (array formulas?), but here goes:


  • Add a helper column to determine the entry time by using formula =HOUR(B#)
  • Add a helper column to determine the departure time by using formula =HOUR(C#)
  • Add a helper column to determine if a customer overnighted more then once. So only full 24h days where the car was parked are counted! If a car left on the same day as he arrived the value is 0. If the car left the first day after arrival the value is 0. If the car left the second day after arrival the value is 1. If the car left the third day after arrival the value is 2. If the car left the fourth day after arrival the value is 3, and so on. This will show how many customers have to be added to each time window (hour).


[TABLE="class: grid, width: 1000"]
<tbody>[TR="bgcolor: #DAE7F5"]
[TH="class: cms_table, align: center"][/TH]
[TH="class: cms_table, align: center"]A[/TH]
[TH="class: cms_table, align: center"]B[/TH]
[TH="class: cms_table, align: center"]C[/TH]
[TH="class: cms_table, align: center"]D[/TH]
[TH="class: cms_table, align: center"]E[/TH]
[TH="class: cms_table, align: center"]F[/TH]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="bgcolor: #000000, align: center"]Customer [/TD]
[TD="bgcolor: #000000, align: center"]In Date-Time[/TD]
[TD="bgcolor: #000000, align: center"]Out Date-Time[/TD]
[TD="bgcolor: #000000, align: center"]Entry time[/TD]
[TD="bgcolor: #000000, align: center"]Departure time[/TD]
[TD="bgcolor: #000000, align: center"]Amount of full (24h) days parked[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]1[/TD]
[TD]9/3/2015 15:00[/TD]
[TD]9/4/2015 15:36[/TD]
[TD]=HOUR(B2)[/TD]
[TD]=HOUR(C2)[/TD]
[TD]=IF(ROUNDDOWN(C2-B2;0)=0;0;ROUNDDOWN(C2-B2;0)-1)[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]2[/TD]
[TD]9/3/2015 15:20[/TD]
[TD]9/4/2015 9:45[/TD]
[TD]=HOUR(B3)[/TD]
[TD]=HOUR(C3)[/TD]
[TD]=IF(ROUNDDOWN(C3-B3;0)=0;0;ROUNDDOWN(C3-B3;0)-1)[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]3[/TD]
[TD]9/5/2015 12:15[/TD]
[TD]9/7/2015 15:59[/TD]
[TD]=HOUR(B4)[/TD]
[TD]=HOUR(C4)[/TD]
[TD]=IF(ROUNDDOWN(C4-B4;0)=0;0;ROUNDDOWN(C4-B4;0)-1)[/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD="align: center"]4[/TD]
[TD]9/5/2015 15:00[/TD]
[TD]9/6/2015 15:03[/TD]
[TD]=HOUR(B5)[/TD]
[TD]=HOUR(C5)[/TD]
[TD]=IF(ROUNDDOWN(C5-B5;0)=0;0;ROUNDDOWN(C5-B5;0)-1)[/TD]
[/TR]
[TR]
[TD="align: center"]6[/TD]
[TD="align: center"]5[/TD]
[TD]9/7/2015 8:00[/TD]
[TD]9/8/2015 18:09[/TD]
[TD]=HOUR(B6)[/TD]
[TD]=HOUR(C6)[/TD]
[TD]=IF(ROUNDDOWN(C6-B6;0)=0;0;ROUNDDOWN(C6-B6;0)-1)[/TD]
[/TR]
[TR]
[TD="align: center"]7[/TD]
[TD="align: center"]6[/TD]
[TD]9/7/2015 13:00[/TD]
[TD]9/9/2015 13:36[/TD]
[TD]etc[/TD]
[TD]etc[/TD]
[TD]etc[/TD]
[/TR]
[TR]
[TD="align: center"]8[/TD]
[TD="align: center"]7[/TD]
[TD]9/10/2015 11:00[/TD]
[TD]9/13/2015 16:52[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]9[/TD]
[TD="align: center"]8[/TD]
[TD]9/10/2015 10:23[/TD]
[TD]9/11/2015 7:44[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]10[/TD]
[TD="align: center"]9[/TD]
[TD]9/11/2015 7:00[/TD]
[TD]9/12/2015 10:36[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]11[/TD]
[TD="align: center"]10[/TD]
[TD]9/11/2015 8:00[/TD]
[TD]9/11/2015 13:52[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[/TR]
</tbody>[/TABLE]






The calculation of the output file works the same as in my first reply, except for two differences:


  • The hour of day is now just number 0-24, instead of based on date/time. So no more 0/24, 1/24, 2/24 etc.
  • To include the overnighting cars I have added a sum formula for all values in column F.


[TABLE="class: grid, width: 1000"]
<tbody>[TR="bgcolor: #DAE7F5"]
[TH="class: cms_table, align: center"][/TH]
[TH="class: cms_table, align: center"]A[/TH]
[TH="class: cms_table, align: center"]B[/TH]
[TH="class: cms_table, align: center"]C[/TH]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="bgcolor: #000000, align: center"]Hour of Day[/TD]
[TD="bgcolor: #000000, align: center"]Count of Customers[/TD]
[TD="bgcolor: #000000, align: center"]Average per day[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]0[/TD]
[TD]=COUNTIFS(DATA!D:D;"<="&OUTPUT!A2;DATA!E:E;">="&OUTPUT!A2)+SUM(DATA!F:F)[/TD]
[TD]=B2/365[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]1[/TD]
[TD]=COUNTIFS(DATA!D:D;"<="&OUTPUT!A3;DATA!E:E;">="&OUTPUT!A3)+SUM(DATA!F:F)[/TD]
[TD]=B3/365[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]2[/TD]
[TD]=COUNTIFS(DATA!D:D;"<="&OUTPUT!A4;DATA!E:E;">="&OUTPUT!A4)+SUM(DATA!F:F)[/TD]
[TD]=B4/365[/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD="align: center"]3[/TD]
[TD]=COUNTIFS(DATA!D:D;"<="&OUTPUT!A5;DATA!E:E;">="&OUTPUT!A5)+SUM(DATA!F:F)[/TD]
[TD]=B5/365[/TD]
[/TR]
[TR]
[TD="align: center"]6[/TD]
[TD="align: center"]4[/TD]
[TD]=COUNTIFS(DATA!D:D;"<="&OUTPUT!A6;DATA!E:E;">="&OUTPUT!A6)+SUM(DATA!F:F)[/TD]
[TD]=B6/365[/TD]
[/TR]
[TR]
[TD="align: center"]7[/TD]
[TD="align: center"]5[/TD]
[TD]etc[/TD]
[TD]etc[/TD]
[/TR]
[TR]
[TD="align: center"]8[/TD]
[TD="align: center"]6[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]9[/TD]
[TD="align: center"]7[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]10[/TD]
[TD="align: center"]8[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]11[/TD]
[TD="align: center"]9[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]12[/TD]
[TD="align: center"]10[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]13[/TD]
[TD="align: center"]11[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]14[/TD]
[TD="align: center"]12[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]15[/TD]
[TD="align: center"]13[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]16[/TD]
[TD="align: center"]14[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]17[/TD]
[TD="align: center"]15[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]18[/TD]
[TD="align: center"]16[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]19[/TD]
[TD="align: center"]17[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]20[/TD]
[TD="align: center"]18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]21[/TD]
[TD="align: center"]19[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]22[/TD]
[TD="align: center"]20[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]23[/TD]
[TD="align: center"]21[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]24[/TD]
[TD="align: center"]22[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]25[/TD]
[TD="align: center"]23[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:
Upvote 0
Thanks again for the help. You are definitely helping me get closer to the solution. Unfortunately, I may not be communicating the logic clearly. I hope this helps explain it.

Here's a sample of five:

Excel 2010
ABCDEF

<tbody>
[TD="align: center"]1[/TD]
[TD="bgcolor: #000000, align: center"]Customer Number[/TD]
[TD="bgcolor: #000000, align: center"]In Date-Time[/TD]
[TD="bgcolor: #000000, align: center"]Out Date-Time[/TD]
[TD="bgcolor: #000000, align: center"]Entry time[/TD]
[TD="bgcolor: #000000, align: center"]Departure time[/TD]
[TD="bgcolor: #000000, align: center"]Amount of full (24h) days parked[/TD]

[TD="align: center"]2[/TD]
[TD="align: center"]1[/TD]
[TD="align: right"]9/3/2015 15:00[/TD]
[TD="align: right"]9/4/2015 15:36[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]0[/TD]

[TD="align: center"]3[/TD]
[TD="align: center"]2[/TD]
[TD="align: right"]9/3/2015 15:20[/TD]
[TD="align: right"]9/4/2015 9:45[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]9[/TD]
[TD="align: center"]0[/TD]

[TD="align: center"]4[/TD]
[TD="align: center"]3[/TD]
[TD="align: right"]9/5/2015 12:15[/TD]
[TD="align: right"]9/7/2015 15:59[/TD]
[TD="align: center"]12[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]1[/TD]

[TD="align: center"]5[/TD]
[TD="align: center"]4[/TD]
[TD="align: right"]9/5/2015 15:00[/TD]
[TD="align: right"]9/6/2015 15:03[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]0[/TD]

[TD="align: center"]6[/TD]
[TD="align: center"]5[/TD]
[TD="align: right"]9/7/2015 8:00[/TD]
[TD="align: right"]9/8/2015 18:09[/TD]
[TD="align: center"]8[/TD]
[TD="align: center"]18[/TD]
[TD="align: center"]0[/TD]

</tbody>
Data



Here's how I manually calculated the average number of cars per day in each hour:

Excel 2010
HIJKLMNOPQRSTUVWXYZAAABACADAEAF
Customer 1
Customer 2
Customer 3
Customer 4
Customer 5
Total Days

<tbody>
[TD="align: center"]1[/TD]
[TD="bgcolor: #000000, align: center"]Manual Count By Hour[/TD]
[TD="bgcolor: #000000, align: center"]0[/TD]
[TD="bgcolor: #000000, align: center"]1[/TD]
[TD="bgcolor: #000000, align: center"]2[/TD]
[TD="bgcolor: #000000, align: center"]3[/TD]
[TD="bgcolor: #000000, align: center"]4[/TD]
[TD="bgcolor: #000000, align: center"]5[/TD]
[TD="bgcolor: #000000, align: center"]6[/TD]
[TD="bgcolor: #000000, align: center"]7[/TD]
[TD="bgcolor: #000000, align: center"]8[/TD]
[TD="bgcolor: #000000, align: center"]9[/TD]
[TD="bgcolor: #000000, align: center"]10[/TD]
[TD="bgcolor: #000000, align: center"]11[/TD]
[TD="bgcolor: #000000, align: center"]12[/TD]
[TD="bgcolor: #000000, align: center"]13[/TD]
[TD="bgcolor: #000000, align: center"]14[/TD]
[TD="bgcolor: #000000, align: center"]15[/TD]
[TD="bgcolor: #000000, align: center"]16[/TD]
[TD="bgcolor: #000000, align: center"]17[/TD]
[TD="bgcolor: #000000, align: center"]18[/TD]
[TD="bgcolor: #000000, align: center"]19[/TD]
[TD="bgcolor: #000000, align: center"]20[/TD]
[TD="bgcolor: #000000, align: center"]21[/TD]
[TD="bgcolor: #000000, align: center"]22[/TD]
[TD="bgcolor: #000000, align: center"]23[/TD]

[TD="align: center"]2[/TD]

[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]

[TD="align: center"]3[/TD]

[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]

[TD="align: center"]4[/TD]

[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]

[TD="align: center"]5[/TD]

[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]

[TD="align: center"]6[/TD]

[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]

[TD="align: center"]7[/TD]
[TD="bgcolor: #F2F2F2"]Total Occurrences[/TD]
[TD="bgcolor: #F2F2F2, align: right"]6[/TD]
[TD="bgcolor: #F2F2F2, align: right"]6[/TD]
[TD="bgcolor: #F2F2F2, align: right"]6[/TD]
[TD="bgcolor: #F2F2F2, align: right"]6[/TD]
[TD="bgcolor: #F2F2F2, align: right"]6[/TD]
[TD="bgcolor: #F2F2F2, align: right"]6[/TD]
[TD="bgcolor: #F2F2F2, align: right"]6[/TD]
[TD="bgcolor: #F2F2F2, align: right"]6[/TD]
[TD="bgcolor: #F2F2F2, align: right"]7[/TD]
[TD="bgcolor: #F2F2F2, align: right"]7[/TD]
[TD="bgcolor: #F2F2F2, align: right"]6[/TD]
[TD="bgcolor: #F2F2F2, align: right"]6[/TD]
[TD="bgcolor: #F2F2F2, align: right"]7[/TD]
[TD="bgcolor: #F2F2F2, align: right"]7[/TD]
[TD="bgcolor: #F2F2F2, align: right"]7[/TD]
[TD="bgcolor: #F2F2F2, align: right"]10[/TD]
[TD="bgcolor: #F2F2F2, align: right"]7[/TD]
[TD="bgcolor: #F2F2F2, align: right"]7[/TD]
[TD="bgcolor: #F2F2F2, align: right"]7[/TD]
[TD="bgcolor: #F2F2F2, align: right"]6[/TD]
[TD="bgcolor: #F2F2F2, align: right"]6[/TD]
[TD="bgcolor: #F2F2F2, align: right"]6[/TD]
[TD="bgcolor: #F2F2F2, align: right"]6[/TD]
[TD="bgcolor: #F2F2F2, align: right"]6[/TD]

[TD="align: center"]8[/TD]

[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]6[/TD]

[TD="align: center"]9[/TD]
[TD="bgcolor: #F2F2F2"]Avg Per Day[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.00[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.00[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.00[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.00[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.00[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.00[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.00[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.00[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.17[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.17[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.00[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.00[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.17[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.17[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.17[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.67[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.17[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.17[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.17[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.00[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.00[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.00[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.00[/TD]
[TD="bgcolor: #F2F2F2, align: right"]1.00[/TD]

</tbody>
Data
For example, Customer 1 entered in the 3 o'clock hour on Sept 3rd and left in the 3 o'clock hour on Sept 4th. When counting, the car was present each once during each hour and twice in the three o'clock hour during it's entire stay. My intent was to do this for each customer, then total the amount of occurrences in each hour and divide by the total number of days being reviewed.

I hope this helps clarify the logic. Thanks...
 
Upvote 0
I see what you mean. The calculation works perfectly when the timeslot you enter is earlier then the timeslot you leave. But when the departure timeslot lies before the arrival timeslot it does not work. In other words, an arrival today at 16:00 and a departure the next day at 17:00 works fine,but an arrival today at 16:00 and a departure the next day at 15:00 will mess up the results.

I have modified the formula. It will now calculate the amount of hours on the day of arrival, the amount of hours on the day of departure (if different from arrival date), and the amount of full days a car has been parked.

The formulas are getting a bit long now, so I won't be posting them in the table but list them below:


  • Column D
    =HOUR(B2),
    Simple formula to calculate the timeslot a car enters.
  • Column E,
    =IF(ROUNDDOWN(C2;0)=ROUNDDOWN(B2;0);HOUR(C2);23)
    This calculates when the car leaves on the first day. If a car does NOT leave the same day it will always show 23. The departure date is then calculated in column G.
  • Column F,
    =ROUNDDOWN(C2;0)-ROUNDDOWN(B2;0)-IF(ROUNDDOWN(C2;0)=ROUNDDOWN(B2;0);0;1)
    This column calculates the total amount of FULL days a car is in the garage.
  • Column G,
    =IF(ROUNDDOWN(B2;0)=ROUNDDOWN(C2;0);"";HOUR(C2))
    If a car does not leave on the same day it arrives it will show the timeslot it left. If a car leaves the same day it arrives it will show "".


[TABLE="width: 1000"]
<tbody>[TR="bgcolor: #DAE7F5"]
[TH="class: cms_table, align: center"][/TH]
[TH="class: cms_table, align: center"]A[/TH]
[TH="class: cms_table, align: center"]B[/TH]
[TH="class: cms_table, align: center"]C[/TH]
[TH="class: cms_table, align: center"]D[/TH]
[TH="class: cms_table, align: center"]E[/TH]
[TH="class: cms_table, align: center"]F[/TH]
[TH="class: cms_table, align: center"]G[/TH]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="bgcolor: #000000, align: center"]Customer Number[/TD]
[TD="bgcolor: #000000, align: center"]In Date-Time[/TD]
[TD="bgcolor: #000000, align: center"]Out Date-Time[/TD]
[TD="bgcolor: #000000, align: center"]Start time[/TD]
[TD="bgcolor: #000000, align: center"]End time (arrival day)[/TD]
[TD="bgcolor: #000000, align: center"]Full days[/TD]
[TD="bgcolor: #000000, align: center"]End time (dep. date)[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]1[/TD]
[TD]9/3/2015 15:00[/TD]
[TD]9/4/2015 15:36[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]2[/TD]
[TD]9/3/2015 15:20[/TD]
[TD]9/4/2015 9:45[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]3[/TD]
[TD]9/5/2015 12:15[/TD]
[TD]9/7/2015 15:59[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD="align: center"]4[/TD]
[TD]9/5/2015 15:00[/TD]
[TD]9/6/2015 15:03[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]





On the output file you need this formula:
=COUNTIFS(DATA!D:D;"<="&OUTPUT!A2;DATA!E:E;">="&OUTPUT!A2)+SUM(DATA!F:F)+COUNTIFS(DATA!G:G;">="&OUTPUT!A2)
 
Upvote 0
It works!!! Thanks for helping me out with this. Your solution is much easier than the VBA I was attempting to write. Have a great holiday weekend!
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,435
Members
452,326
Latest member
johnshaji

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