I have an excel worksheet (macro free) set up as follows;
Column W = Shift Start Time
Column X = Shift End Time
Column AE:BB are named 00:00 to 23:00 respectively.
I am trying to count the manpower available by hour e.g. if 1 shift is Start Time 10:00 and Finish 15:00 - this will count 1 for hours 11:00,12:00,13:00 (within AE:BB Table).
The formula currently used is
=COUNTIFS($B$5:$B$76,"<="&AE4,$D$5:$D$76,">="&AE4)
This works when the Shift start time is earlier than finish in one 24 hour period (e.g. 07:00 - 18:00). However, when a night shift finishes the next working day (E.g. 19:00-07:00) any manpower available within that time will not calculate.
Is there a way to incorporate a criteria that considers if Cell W> adjacent cell X into the formula?
Example Source
Current Results
Expected Results
Based on the shift table as follows:
Note that an additional column was added to the shift hours. It was my method for creating an end time on the following day. In Y5 I placed the following formula and copied down:
=IF(X5<W5,X5+1,X5)
It adds 1 to the time when the end time is less than the start time. This essentially adds 1 day to the time. However as long as the cell is formatted to only display time like the other cells, the 1 day is not observed by the user. This modified end time is then used for checking counts.
Place the following formula in AE5 and copy to the right as needed:
=COUNTIFS($W$5:$W$9,"<="&AE4,$Y$5:$Y$9,">"&AE4)+COUNTIFS($W$5:$W$9,"<="&AE4+1,$Y$5:$Y$9,">"&AE4+1)
Check once for regular times and check again for times in the next day and combine the results. Not the > instead of >=. If a shift ends at 1700 then the shift is not available to work from 1700-1800. In your previous example you had them available for the start time block and the end time block. You should count 1 or the other but not both unless you have something that states shift can work 1 hour past their end time or something similar.
Related
In the following picture I have a total time taken to fix an issue by Cell B2 and C2 being filled in. They post a time stamp when they are changed. Cell M2 is the total time between the two actions.
In the next picture I have a Macro that adds a new row every time the button is pressed. For this question I only need to use Columns A,B,C,J. A&B are just the time stamp of when the marco was ran. Column C is the new "layer total" so that value will increase to the nearest multiple of 20 (B7). Column J is the average time per layer between the last two rows. Example is that it takes 1.5 min(J20) per layer between layers 201(C20) and 185(C19).
My question is (after all this time) if there is a way to use the LOOKUP function to find all the pause times in Picture 1 between two layer values from Picture 2. Example: Find all the pause times between layers 140 and 162. Then add those up pauses up into a single value?
Look at SUMIFS.
Example:
=SUMIFS(PausesSheet!M4:M100,PausesSheet!C4:C100,">=140",PausesSheet!C4:C100,"<=162")
The ">=140" and "<=162" (from your example) can be replaced with formula, e.g. ">=" & C8, ... "<=" & C9 , which you can use all the way down on your second worksheet.
I have a spreadsheet that lists the date and time of an event in the same cell (mm/dd/yy h:mm). I need to find a way to count how many events took place between a certain time range in a Hourly Basis.
I could sum if the cell contains dates only however the cell contains with date which i am unable to get the values.
Basically, all datas are in cell A, so i need to count how many events happened at 6am, 7am , and so on... as on hourly basis.
Your column A looks like properly formatted date & time value, so its manipulation is easy. If it's not (ie, not date but text) you should first convert it to date value.
=DATE(MID(A2,7,4), MID(A2,4,2), LEFT(A2,2)) + TIME(MID(A2,12,2), MID(A2,15,2), RIGHT(A2,2))
Say this was C2. Now that column C is date & time, set $D$2 to date to query(ex 2017-03-26), E2 to start time(ex 6:00), and F2 to end time(ex 7:00), then you can count events from 6:00 to 7:00 like this:
=COUNTIFS(C:C,">="&($D$2+E2), C:C,"<"&($D$2+F2))
Sample file is here and its screenshot is below.
If the times spanned different dates and you still wanted to see how many events happened in a particular hour of the day, you would need an array-type formula, e.g. if the start time in hours (entered as a normal number) is in C2
=SUMPRODUCT(--(HOUR($A$2:$A$10)=C2))
or if the start hour is entered as a time
=SUMPRODUCT(--(HOUR($A$2:$A$10)=HOUR(C2)))
I have a list of periods (given by period start, period end) in Excel and I have to calculate exactly how many months (as a fraction) are during that period.
E.g. if given a period January 15th to March 7th, then this would be
15-01-2015 until 31-01-2015 = 17 days
01-02-2015 until 28-02-2015 = 28 days
01-03-2015 until 07-03-2015 = 7 days
Months during period = 17/31 + 28/28 + 7/31 = 1,774193548 months
Note that in this calculation, start date and end date are both counted as part of the period.
As the periods can be anything, then I haven't been able to figure out to calculate this with an Excel formula (or if it's even possible).
Any ideas?
Well it's not pretty, but if you have a start date at A1 and an end date at A2, then:
=12*(YEAR(A2)-YEAR(A1))+MONTH(A2)-MONTH(A1) +
(DAY(A2)/(DATE(YEAR(A2),MONTH(A2)+1,1)-DATE(YEAR(A2),MONTH(A2),1))) -
((DAY(A1)-1)/(DATE(YEAR(A1),MONTH(A1)+1,1)-DATE(YEAR(A1),MONTH(A1),1)))
The way this works is:
12*(YEAR(A2)-YEAR(A1)): Difference in year times 12.
+MONTH(A2)-MONTH(A1): (plus) Difference in months.
+(DAY(A2)/(DATE(YEAR(A2),MONTH(A2)+1,1)-DATE(YEAR(A2),MONTH(A2),1))): (plus) Day of end date divided by the total days in end month, calculated by the diff between that month's 1st and the following month's 1st.
-((DAY(A1)-1)/(DATE(YEAR(A1),MONTH(A1)+1,1)-DATE(YEAR(A1),MONTH(A1),1))) (minues) Day of start (minus 1 to not count that day) month divided by the total days in start month.
Of course you duplicate that for any set of cells...
Assuming column A lists the start dates and column B lists the end dates:
=SUMPRODUCT((1+B1:B3-A1:A3)/DAY(DATE(YEAR(A1:A3),MONTH(A1:A3)+1,)))
Note: you will need to increase the depth of the ranges to suit your needs... just change the 3s to a deeper row number.
UPDATE
Based upon your feedback and new requirement, here is a version of the above formula that will calculate the total, one row at a time:
=(1+B1-A1)/DAY(DATE(YEAR(A1),MONTH(A1)+1,))
UPDATE 2
Based on new information that the interval on one row can exceed one month, here is a new version of the formula:
=DATEDIF(A1-DAY(A1)+1,B1,"m")-1+(1+EOMONTH(A1,0)-A1)/DAY(DATE(YEAR(A1),MONTH(A1)+1,))+(B1-EOMONTH(B1,-1))/DAY(DATE(YEAR(B1),MONTH(B1)+1,))
IMPORTANT NOTE: After confirming this formula you will need to apply GENERAL number formatting to the cell. This is because Excel will try to apply DATE number formatting unnecessarily.
Why don't you use:
=12*YEARFRAC(StartDate,EndDate)
I generally ask Python or VBA questions, but this has been annoying me for the past 4.5 hours and i need it to finish a macros and i'm just getting div/0 error.
In excel i have five columns:
1. Date when the item entered the queue (A)
2. time when the item entered the queue (B)
3. Date when the item left the queue (C)
4. time when the item left the queue (D)
5. time the item was in the queue (E)
I need the average of time of the items that entered and left the queue between 16:00 yesterday and 16:00 today. Also for it to ignore numbers < than 1 (because if an item has been there for over 24 hours the default value is negative).
I tried tried this and no results :(
=AVERAGEIFS(E1:E4,A1:A4,"=today()-1",B1:B4,">16:00",C1:C4,"=today()",D1:D4,"<16:00")
Any ideas would be appreciated! Thanks in advance :)
Your formula is saying this:
=AVERAGEIFS(E1:E4,A1:A4,"=today()-1",B1:B4,">16:00",C1:C4,"=today()",D1:D4,"<16:00")
Take the average of E1:E4 if...
A1:A4 are equivalent to the string "=today()-1"
B1:B4 are equivalent to the string ">16:00"
C1:C4 are equivalent to the string "=today()"
D1:D4 are equivalent to the string ">16:00"
What you want it to say is:
Take the average of E1:E4 if...
A1:A4 are equivalent to the result of the formula =today()-1
B1:B4 are less than 16 hours
C1:C4 are equivalent to the result of the formula =today()
D1:D4 are less than 16 hours
Let's tackle 2 and 4 first.
In Excel, 1 day (24 hours) = 1. Times are stored as decimal values as a percentage of a day:
1 day = 1
1 day = 24 hours
1 hour = 1 / 24
16 hours = 16/24 = 2/3
So instead of B1:B4,">16:00" you should rewrite the formula as:
B1:B4,">"&2/3
The & concatenates the greater than sign, and 2/3 will give the decimal value equivalent to 16:00. In the end you will get a string equal to ">.6666666666"
(You can also just use B1:B4,">.6666666666666" if you'd like)
For items 1 and 3, you don't need to use quotes at all. So instead of A1:A4,"=today()-1" you can just use the following:
A1:A4,today()-1
C1:C4,today()
Putting this all together, the following formula should work:
=AVERAGEIFS(E1:E4,A1:A4,today()-1,B1:B4,">"&2/3,C1:C4,today(),D1:D4,"<"&2/3)
If you are looking for "items that entered and left the queue between 16:00 yesterday and 16:00 today" isn't it possible that some of those entered the queue today (or left the queue yesterday)? If so you would need to check for items that entered today as well, surely? To do that is difficult with AVERAGEIFS function - it might be easier to use an "array formula" like this:
=AVERAGE(IF(A1:A4+B1:B4>=TODAY()-1/3,IF(C1:C4+D1:D4<TODAY()+2/3,E1:E4)))
confirmed with CTRL+SHIFT+ENTER
I'm assuming that the formula doesn't have to explicitly deal with your negative values because those will only occur for items which have been there for more than 24 hours and the IF functions will exclude those anyway...
If you want to do the same with AVERAGEIFS you'd need to create two additional columns with the entry/exit dates/times added, e.g. if column G is the sum of columns A and B and column H is the sum of columns C and D you could use this version
=AVERAGEIFS(E1:E4,G1:G4,">="&TODAY()-1/3,H1:H4,"<"&TODAY()+2/3)
Note that I used >= and < deliberately to avoid double-counting/non-counting across several days
I have a cell with the format "mm/dd/yyyy hh:mm:ss". I want to auto increment the minute, but when I manually auto increment after selecting only that cell, it increments the day. To make it increment the minute, I have to manually copy the cell below, add one minute, select both and THEN increment. Is it possible to, in VBA, specify what part of the cell I want to be incremented when I use the
Selection.AutoFill
function and only have one cell selected? As it is, recording the macro gives me
Selection.AutoFill Destination:=Range("BU2:BU3"), Type:=xlFillDefault
In Excel dates and times are stored differently then in other languages.
From http://www.cpearson.com/excel/datetime.htm
Excel stores dates and times as a number representing the number of
days since 1900-Jan-0, plus a fractional portion of a 24 hour day:
ddddd.tttttt
This is called a serial date, or serial date-time.
If you want to increment by minute then you should add the fraction of a day that is equal to one minute
Minutes in a day = 1440
1 / 1440 = 0.00069444
Set your auto increment function to 0.00069444 and it should work they way you expect.