x404.co.uk http://www.x404.co.uk/forum/ |
|
Help with Excel formula http://www.x404.co.uk/forum/viewtopic.php?f=3&t=8731 |
Page 1 of 2 |
Author: | Blue_Nowhere [ Mon Jun 07, 2010 11:24 pm ] |
Post subject: | Help with Excel formula |
Hi all, Right. Excel problem....I've been playing with it for a while but can't quite figure it out... I need to embed calculations to automatically give me the duration for a Priority 1 incident. What we have to work with: create date/time and close date/time The duration time works on a · 9 hour day · 8:00 to 17:00 · Weekends are excluded Hours outside these times are excluded from the calculation. I can't work out how to attached a file, so basically what I have is...1/1/1900 4.30 AM and 3/1/1900 7.30PM in all cells. A1 and B1 are formatted for date and C1 and D1 for time. So you get: 1/1/1900 - 3/1/1900 - 4.30AM - 7.30PM If this doesn't make sense, or anyone needs me to PM them the file let me know. Thanks for any help in advance! PS Something special to whoever solves it (I'll write a new Forum Story with them as the main character or something) Edit: Also, if possible, I'd like the outcome to be something like 2 days 13 hours. (Closest to 15 minutes, sorry I'm being picky but it's important) |
Author: | big_D [ Tue Jun 08, 2010 5:46 am ] |
Post subject: | Re: Help with Excel formula |
You should use the actual year as well, otherwise it won't calculate properly over year-end... I'll see if I can have a look at it later. |
Author: | Blue_Nowhere [ Tue Jun 08, 2010 6:49 am ] |
Post subject: | Re: Help with Excel formula |
Thanks Dave, the actual year is in there too. |
Author: | big_D [ Tue Jun 08, 2010 6:59 am ] |
Post subject: | Re: Help with Excel formula |
Can you not simply use a date/time field for logged and a date/time field for resolved? As opposed to having 2 separate cells for date and time? That could make the calculation a bit easier to work with (I think, just starting to look at it now). Edit: Closer reading, you have the complete date and time in all cells, just showing different aspects in A/B and C/D? |
Author: | big_D [ Tue Jun 08, 2010 8:14 am ] |
Post subject: | Re: Help with Excel formula |
Okay, harder than I thought... I think the easiest way is with a custom function (unless anyone else has any ideas). I've got the function working correctly for jobs that start and end on the same day. Now need to calculate in days and weekends... |
Author: | Fogmeister [ Tue Jun 08, 2010 8:19 am ] |
Post subject: | Re: Help with Excel formula |
Which version of Excel? |
Author: | Fogmeister [ Tue Jun 08, 2010 8:40 am ] | |||||||||
Post subject: | Re: Help with Excel formula | |||||||||
OK, done. It's a lot easier with Excel 2007 though as you can use the NETWORKDAYS() function to exclude weekends I don't think there's an easy way to do that in 2003. I haven't compressed it down so you can see all the working. You should be able to get it straight out into Net Days and Net Hours though. Using this format...
Net Days in your example shows 2 and net hours shows 15. Also works when time from is after time to (i.e. removes a day and adds time, etc...) Hope this helps. ![]() |
Author: | big_D [ Tue Jun 08, 2010 9:27 am ] |
Post subject: | Re: Help with Excel formula |
It doesn't work, if you are on the same day! (E.g. a call is openened on 01.06.2010 and is closed on 01.06.2010, the NETWORKDAYS function still returns 1!) |
Author: | Fogmeister [ Tue Jun 08, 2010 9:28 am ] | |||||||||
Post subject: | Re: Help with Excel formula | |||||||||
LOL ![]() OK, I'll work on it ![]() |
Author: | Fogmeister [ Tue Jun 08, 2010 9:38 am ] | |||||||||
Post subject: | Re: Help with Excel formula | |||||||||
OK,
That should do it ![]() |
Author: | big_D [ Tue Jun 08, 2010 11:50 am ] |
Post subject: | Re: Help with Excel formula |
So, pretty much have a programmed solution... Post it in a bit. One quick question, do you count 9 hours as 1 day or 24 hours as one day? I am doing whole days as simply + 1, but when the start time on the first day and the end time on the last day would make 9 hours (or more) in total, do you want that to be +1 day or +9 hours? E.g. 01/06/2010 04:30 to 04/06/2010 is giving, currently, 4 days and 9 hours, should that be so, or 5 days? |
Author: | big_D [ Tue Jun 08, 2010 12:16 pm ] | |||||||||
Post subject: | Re: Help with Excel formula | |||||||||
So, it is still a bit quick and dirty, and you'll need to do some proper testing, I've used a couple of simple dates and it seems to work. It returns a string, currently, of days:hours:minutes. We can change this as needed to, to be a date for example. It excludes weekends. It works works correctly with the working day of 9 hours (truncates times outside of 08:00 to 17:00), these are the constants at the top of the function. You can change these as needed. It works on 24 hour days! If you want 9 hour days, pay attention to the comment at the end to recalculate the number of days and hours in 9s (one formula needs changing). E.g. currently 01/06/2010 07:30 until 08/06/2010 comes out at 6 days, 9 hours, changing the 24 for 9 in the calculation would give 7 days! To set this up, open the VBA editor in Excel (Alt+F11) and insert a new module. Then copy and paste the code below into the module and save it. Then, on the worksheet, simply enter the function name into the required cell: E.g. A1 = start date/time, B1 = end date/time, C1 would then be =elapsed(A1,B1) If you really need to split out the date and time into separate cells, you will need a combo cell with it put back together or you will need to re-write the function to accept the date and time broken up.
|
Author: | big_D [ Wed Jun 09, 2010 7:25 am ] |
Post subject: | Re: Help with Excel formula |
Erm, Blue? Did that help? |
Author: | Blue_Nowhere [ Wed Jun 09, 2010 10:43 pm ] |
Post subject: | Re: Help with Excel formula |
Sorry for the delay guys - been busy moving into a new apartment and have been in and out of the office. I had it to the point where I could get it working if it closed and opened on the same day but no further. Will give the below a go shortly and see how it goes. Will update soon - thanks for the help guys, appreciated! |
Author: | Blue_Nowhere [ Wed Jun 09, 2010 11:23 pm ] |
Post subject: | Re: Help with Excel formula |
Ok Dave - I've created a module- pasted your code in...no problems so far. However I can't quiet work out how to 'call' the functions into the worksheet. I've tried just entering the function name, or putting an = before. I think I might be being a simpleton and therefor might need some more detailed step by step instructions. ![]() |
Page 1 of 2 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |