+ Reply to Thread
Results 1 to 18 of 18

Formula to substract a range of time from a range of time

  1. #1
    Registered User
    Join Date
    04-28-2017
    Location
    Pakistan
    MS-Off Ver
    2013
    Posts
    10

    Formula to substract a range of time from a range of time

    Hello Everyone,

    I am fairly new to the Excel world and upon working for a few days on Excel came to know the power and versatility of this piece of software has to offer, and would love to learn more on it.

    Currently i have a requirement as mentioned below and would greatly appreciate the help extended.

    Scenario 1:

    I have a production window and non production window in a day.

    I have two time columns as Started and Ended times. This range can start within the production window, say (7am-5pm) and end in a non production window say (5pm-6am) within a day or vise versa.

    Requirement:

    I need a formula to calculate the exact number of hours that fall in the non production window and get it subtracted from the production window within 24 hours.

    Scenario 2:

    The time range can go in several months as well so need to take out the off production window and get it subtracted from the production window so i will have the actual hit to the production hours.


    I would really really appreciate if someone can help me out on this please.

    Regards

    Nabeel.

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Formula to substract a range of time from a range of time

    Will you please attach a SMALL sample Excel workbook (10-20 rows of data is usually enough)? Please don't attach a picture of one (no-one will want to re-type all your stuff before starting).

    1. Make sure that your sample data are truly REPRESENTATIVE of your real data. The use of unrepresentative data is very frustrating and can lead to long delays in reaching a solution.

    2. Make sure that your desired solution is also shown (mock up the results manually).

    3. Make sure that all confidential information is removed first!!

    4. Try to avoid using merged cells. They cause lots of problems!

    Unfortunately the attachment icon doesn't work at the moment. So, to attach an Excel file you have to do the following: Just before posting, scroll down to Go Advanced and then scroll down to Manage Attachments. Now follow the instructions at the top of that screen.
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  3. #3
    Registered User
    Join Date
    04-28-2017
    Location
    Pakistan
    MS-Off Ver
    2013
    Posts
    10

    Re: Formula to substract a range of time from a range of time

    Hi Glenn,

    Thanks for the reply and apologies from my end for responding to you late on this. I am attaching a sample sheet which has the following info.

    1- Start Downtime
    2- End Downtime
    3- Total Duration of downtime.

    24 Hours Breakup of On and Off Production

    1- Production hours time.
    2- Off Production Hours time.

    Requirement:

    1- Formula should be able to calculate the actual on production hours downtime during the complete duration.
    2- Formula should be able to calculate the actual off production hours downtime during the complete duration.
    3- Some accounts off production times will vary for e.g some will be completely switched off on Sat and Sun, some will be working on Sat with less number of production hours etc.



    I have put in only 2 rows which are the two scenarios i have, once i have the formula, i can extend it through out the worksheet. I would really appreciate if the formula could be changed according to the working days and hours.

    I really really appreciate the help from your side. Thanks a lot!
    Attached Files Attached Files
    Last edited by nabeel.rehman; 05-03-2017 at 07:40 PM.

  4. #4
    Registered User
    Join Date
    04-28-2017
    Location
    Pakistan
    MS-Off Ver
    2013
    Posts
    10

    Re: Formula to substract a range of time from a range of time

    Hi Glenn,

    Can you kindly let me know if you were able to go through the sample sheet. I honestly appreciate the help you are extending and apologize for being on your nerves for this. Please do let me know whenever it will be feasible for you to have a look and share an update with me please.
    Would greatly appreciate it.

    Regards

    Nabeel

  5. #5
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    18,509

    Re: Formula to substract a range of time from a range of time

    Hello Nabeel and Welcome to Excel Forum.
    This proposed solution employs a helper table and a change in the format of the production hours table, highlighted in green.
    The formula that populates the helper table is:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Note: The days listed in row 4 are not needed, they are just there to indicate which dates in row one (necessary) are weekend dates.
    The dates in row 1, beginning with column H, are generated using the formulas and will adjust as the start and end dates for the projects are adjusted.
    The formula that populates column E is: =SUM(H2:AC2)
    The formula that populates column F is: =D2-E2
    Columns E and F are custom formatted [h]:mm "Hours"
    Let us know if you have any questions.
    Attached Files Attached Files
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  6. #6
    Registered User
    Join Date
    04-28-2017
    Location
    Pakistan
    MS-Off Ver
    2013
    Posts
    10

    Re: Formula to substract a range of time from a range of time

    Hi Jete,

    Wow, this is great!!! Thanks a lot for the help. This is exactly what i needed. There is one more requirement though as i forgot to mention.

    This sheet is great as it is, but some of the accounts have different production hours on Sat and Sun, weekdays remain the same as it is but some have same weekend timings to which this spreadsheet will fit in perfectly! but for others, sat and sunday has a different slot of production timings.
    Will this be able to cater for different Sat and Sunday timings too or would need some tweaks on the formula?



    I really appreciate the help you have extended. Would really appreciate it, if you can address the different production hours issue on Sat and Sun on the same sheet please?

    Regards

    Nabeel ur rehman.
    Last edited by nabeel.rehman; 05-11-2017 at 05:27 PM.

  7. #7
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    18,509

    Re: Formula to substract a range of time from a range of time

    Hello Nabeel,

    It would help if you could upload a sample spreadsheet showing examples of accounts that have different production hours for the weekends. Also please include an example of where the formula gives incorrect on and off production timings based on PM start time and AM end time.

  8. #8
    Registered User
    Join Date
    04-28-2017
    Location
    Pakistan
    MS-Off Ver
    2013
    Posts
    10

    Re: Formula to substract a range of time from a range of time

    Hi There,

    Thanks for your quick response. PM-AM time difference was my bad as i was not putting the details correctly. It is working fine as i double checked on it again that is why i had edited my earlier comment and i really apologize for the inconvenience.

    I am attaching the same sheet that you shared with me, with the same data just adding Sat and Sunday timings on the next sheet.

    Your help is greatly appreciated.

    P.S: I am aware that i am asking for too much, and i really thank you for that. What i would love to understand is a short summary of the formula logic you have put in instead of just blindly copy pasting and using it, whenever you get the time and if possible for you. My main goal is to learn Excel nested formulas
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    04-28-2017
    Location
    Pakistan
    MS-Off Ver
    2013
    Posts
    10

    Re: Formula to substract a range of time from a range of time

    Hi,

    I am attaching the snapshot for the problem i get while changing the production times. Kindly have a look.
    Attached Images Attached Images

  10. #10
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    18,509

    Re: Formula to substract a range of time from a range of time

    As to post #8 where the production hours for Saturday are different than the production hours for Sunday a possible solution is make an adjustment to the green highlighted table and add another conditional layer to the formula as in:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    As to post #9 where the time has been changed to 2:00 PM, I'll have to look at that a little closer and try and get back to you with a possible solution.

  11. #11
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    18,509

    Re: Formula to substract a range of time from a range of time

    The formula used in the attached file seems to have solved the issue of end times being changed from AM to PM. This formula is written in such a way that you will need to schedule Saturday's and Sunday's times separately even if they are the same, as seen in the attachment. Please test the formula rigorously, as I have only tested minimally.
    Let us know if you have any questions.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    04-28-2017
    Location
    Pakistan
    MS-Off Ver
    2013
    Posts
    10

    Re: Formula to substract a range of time from a range of time

    Hi Jete,

    Thanks for the response. PM-AM issue has been sorted out Now there is a different issue i.e. I am adding more start and end times in the sheet and upon doing so the Production Hours turn out to be zero for all the fields. Attached are the snapshots. I have checked extending the formula for all the data and as a transpose too but with same results.
    Attached Images Attached Images

  13. #13
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    18,509

    Re: Formula to substract a range of time from a range of time

    Hello Nabeel,

    Please upload the spreadsheet from which the screen shot was taken.

    Let us know if you have any questions.

  14. #14
    Registered User
    Join Date
    04-28-2017
    Location
    Pakistan
    MS-Off Ver
    2013
    Posts
    10

    Re: Formula to substract a range of time from a range of time

    Hi Jete,

    Kindly find attached sheet with the data in it.

  15. #15
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    18,509

    Re: Formula to substract a range of time from a range of time

    Please see if the results are as expected. I had to make an adjustment to the formula, adding =IF(H$9< ROUND($B10,0),"",... to the beginning.
    Let us know if you have any questions.
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    04-28-2017
    Location
    Pakistan
    MS-Off Ver
    2013
    Posts
    10

    Re: Formula to substract a range of time from a range of time

    Hi Jete,

    Once i add more data rows below for eg. b39 and C39, the on production still shows zero while off production shows the whole duration hours. Attached is the file.

    The problem that i seem to be having is, when i add more data rows, i can extend the formula in the adjacent cells i.e. columns C,D,E,F which is working. But for the formula columns which currently are ending on column EC, if i add another data row that formula should get extended to ED,EF,EG accordingly and i can get the formula extended in the column vertically but it shows blank after EC.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by nabeel.rehman; 05-12-2017 at 06:14 PM.

  17. #17
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    18,509

    Re: Formula to substract a range of time from a range of time

    The range of the formula has been extended horizontally to column NZ so that it will accommodate 383 days between the minimum date in column B and the maximum date in column C. The range has also been extended vertically to row 100.
    The array entered formula* in cell H9 has been changed so that it reads:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    *Remember that array entered formulas need to be activated by simultaneously pressing the Ctrl, Shift and Enter keys while the cell is in edit mode.
    Likewise the formula in I9 has been changed to read:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    The formula is then copied out to column NZ also.
    If you need to extend the start and end times further than row 5000 those two formulas will need to be changed again to increase the range.
    If you need to have a longer range of dates than 383 days you can select the range NZ9:NZ100 and drag the fill handle to the right as far as needed.
    Note that extending the range which is populated by the formula will increase the size of the file as may be evidenced by the fact that the changes made to the file since it was attached to to post #16 is approximately five fold (200KB).
    Let us know if you have any questions.
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    04-28-2017
    Location
    Pakistan
    MS-Off Ver
    2013
    Posts
    10

    Re: Formula to substract a range of time from a range of time

    Hi Jete,

    Apologies for responding to you late on this. Just wanted to let you know that i was a bit engaged and didn't get enough time to test the sheet thoroughly.

    I will get back to you as soon as i verify all the scenarios. Thanks a lot for all the extended help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Excel Formula to Calculate Time Span Between Different Time Range.
    By omershafiq2012 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-06-2015, 08:28 AM
  2. [SOLVED] COUNTIF Time Range - Time Range provided in Cells
    By Eaks77 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-02-2015, 11:12 PM
  3. [SOLVED] Counting values in a time range - when the time range crosses midnight
    By dlocos in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-24-2014, 04:27 AM
  4. Calculate if Time range appears in an other Time range
    By bajdr47 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-25-2013, 02:50 AM
  5. compare time values - current time with time in cell range?
    By wyattea in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-13-2013, 11:28 PM
  6. send to range, popup box to input what the range should be each time/select range
    By lax2734 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-26-2012, 01:37 AM
  7. [SOLVED] How do I substract numbers in range like this: Substract(a1..a10)
    By Paulo in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 11-17-2005, 12:50 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1