+ Reply to Thread
Results 1 to 9 of 9

Calculating total hours from a single cell that lists a timeframe

  1. #1
    Registered User
    Join Date
    06-14-2019
    Location
    Southern California
    MS-Off Ver
    Home and Student 2016
    Posts
    2

    Calculating total hours from a single cell that lists a timeframe

    Hi! I am stumped on this one, trying to figure out how to calculate total hours from a single cell that lists hours scheduled to work.
    I know the simple solution is to split start time and end time into two different cells, however, that is not an option because I am trying to convert hours from an exported report that cannot be reconfigured at this time.

    For example, I am looking for a formula that will return the total hours scheduled for C3:
    C3 6:00A-2:00P

    Any tips would be appreciated!

  2. #2
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    2007, 365
    Posts
    10,154

    Re: Calculating total hours from a single cell that lists a timeframe

    Hello Ashgemaehlich. Welcome to the forum.

    Before embarking:
    1. Are we to understand that the start/end times can span a Midnight?
    2. And with that question in mind and this quote.
      I know the simple solution is to split start time and end time into two different cells, however, that is not an option because I am trying to convert hours from an exported report that cannot be reconfigured at this time.
    3. Does this rule out helper columns as well?


    If so this may take a long complicated formula. It could be a while.


    This is what I have so far. I am hopeful it can be shortened/simplified.
    Formula: copy to clipboard
    Please Login or Register  to view this content.




    C
    D
    3
    6:00A-2:00P
    8:00
    4
    11:00P-2:00A
    3:00
    5
    7:00P-4:00A
    9:00
    6
    11:00A-1:00A
    14:00
    Last edited by FlameRetired; 06-14-2019 at 09:06 PM.
    Dave

  3. #3
    Valued Forum Contributor Root_'s Avatar
    Join Date
    07-29-2017
    Location
    _
    MS-Off Ver
    2010+
    Posts
    382

    Re: Calculating total hours from a single cell that lists a timeframe

    Here is a shorter formula to try:

    =MOD(SUMPRODUCT(TRIM(SUBSTITUTE(SUBSTITUTE(UPPER(MID(C3,CHOOSE({1,2},FIND("-",C3)+1,1),CHOOSE({1,2},99,FIND("-",C3)-1))),"P"," P"),"A"," A"))*{1,-1}),1)

  4. #4
    Forum Expert
    Join Date
    07-20-2011
    Location
    mysore
    MS-Off Ver
    Excel 2007
    Posts
    4,500

    Re: Calculating total hours from a single cell that lists a timeframe

    In B2 then copied down
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by kvsrinivasamurthy; 06-15-2019 at 03:47 AM.
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  5. #5
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2003; 2007
    Posts
    7,034

    Re: Calculating total hours from a single cell that lists a timeframe

    Or can try
    =mod(lookup(9^9,right(left(substitute(substitute(c3,"a"," am"),"p"," pm"),len(c3)+3),{6,7,8})+0)-lookup(9^9,left(substitute(substitute(c3,"a"," am"),"p"," pm"),{6,7,8})+0),1)
    Please Login or Register  to view this content.
    Samba

  6. #6
    Forum Guru XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    6,865

    Re: Calculating total hours from a single cell that lists a timeframe

    Yet another!

    =MOD(MMULT(0+TRIM(MID(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C7,"-",REPT(" ",2)),"A"," A"),"P"," P"),{1,9},8)),{-1;1}),1)

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  7. #7
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,767

    Re: Calculating total hours from a single cell that lists a timeframe

    Here is another one:
    Enter formula in D3 and copy down
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    v C D
    3 6:00A-2:00P 8:00
    4 11:00P-2:00A 3:00
    5 7:00P-4:00A 9:00
    6 11:00A-1:00A 14:00
    Last edited by AlKey; 06-15-2019 at 05:51 PM.
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  8. #8
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    2007, 365
    Posts
    10,154

    Re: Calculating total hours from a single cell that lists a timeframe

    Thank you for another lesson.

    Root_, samba_ravi, XOR LX and AlKey.

    MOD(sum,1)

    Never occurred to me! (Groan!) That shortened my efforts a lot.

    About the same as others above though not as short. Used REPLACE first.

    =MOD(SUMPRODUCT((TRIM(MID(SUBSTITUTE(REPLACE(REPLACE(C3,LEN(C3),0," "),FIND("-",C3)-1,0," "),"-",REPT(" ",20)),{1,20},20)))*{-1,1}),1)
    Last edited by FlameRetired; 06-15-2019 at 11:01 PM.

  9. #9
    Registered User
    Join Date
    06-14-2019
    Location
    Southern California
    MS-Off Ver
    Home and Student 2016
    Posts
    2

    Re: Calculating total hours from a single cell that lists a timeframe

    I can use helper cells if they are linked on a different sheet, I will be "exporting" a master data sheet and having all data pulled from there for calculations

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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