+ Reply to Thread
Results 1 to 10 of 10

Formula to Format how time (hh:mm:ss) is displayed based on specific criteria?

  1. #1
    Registered User
    Join Date
    01-31-2015
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    91

    Formula to Format how time (hh:mm:ss) is displayed based on specific criteria?

    I am trying to write a formula that pulls data from cell A1 on Sheet 2 into cell B1 on Sheet 1

    The data in A1 is in hh:mm:ss format.

    Using Cell A1 with a value of 00:06:20 as a working example
    I would like the formula to do one of two things, starting at A2 for every cell in Column A on Sheet 2 depending upon if a cell has an entry that is either hour, minutes & seconds (01:06:20) or just minutes and seconds (00:06:20).

    If a cell has an entry like 01:06:20 then the formula should return 01:06:20 “hh:mm:ss”

    If a cell has an entry like 00:06:20 then the formula should return 00:06:20 “mm:ss”

    I have tried to have the formula use the first “:” character as a delimiter and then check if the two characters before it “00:” are any other character then “0”. (meaning the value is 0 hours 06 minutes and 20 seconds) and then return the appropriate format as described below.

    If true then format the cell as general and insert “06:20”

    If false then format the cell as general and insert “01:06:20”

    Then move to next cell in range “A2:A) and repeat until the last cell

    Of course the time value in each cell A1 on Sheet 2 will be different but the constant character will be the FIRST “:” and that any number before it apart from “0” will mean it is an hh:mm:ss value.

    I have been at this all day and I cannot get the formula to only use the first “:” as a delimiter and then look at the two numbers before it.

    Many thanks

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Formula to Format how time (hh:mm:ss) is displayed based on specific criteria?

    Not sure quite what you want to do, but you can determine if there are any hours like
    =IF(A2<1/24,"mm:ss","hh:mm:ss")

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Formula to Format how time (hh:mm:ss) is displayed based on specific criteria?

    Select column A and apply custom format formula:
    Please Login or Register  to view this content.
    Ben Van Johnson

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Formula to Format how time (hh:mm:ss) is displayed based on specific criteria?

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not provided the required cross-post link(s) here.

    Please see Forum Rule #3 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important.

    (Note: this requirement is not optional. No help to be offered until the link is provided.)
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  5. #5
    Registered User
    Join Date
    01-31-2015
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    91

    Re: Formula to Format how time (hh:mm:ss) is displayed based on specific criteria?

    Quote Originally Posted by Fluff13 View Post
    Not sure quite what you want to do, but you can determine if there are any hours like
    =IF(A2<1/24,"mm:ss","hh:mm:ss")
    Thank you Fluff13 - this has given me a start.

  6. #6
    Registered User
    Join Date
    01-31-2015
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    91

    Re: Formula to Format how time (hh:mm:ss) is displayed based on specific criteria?

    Quote Originally Posted by protonLeah View Post
    Select column A and apply custom format formula:
    Please Login or Register  to view this content.
    Thank you, I will give it a try.

  7. #7
    Registered User
    Join Date
    01-31-2015
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    91

    Re: Formula to Format how time (hh:mm:ss) is displayed based on specific criteria?

    My apologies to all for cross posting, it will not happen again.

    Also asked here https://www.mrexcel.com/board/thread...ng-om.1137860/ but received no replies.

  8. #8
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Formula to Format how time (hh:mm:ss) is displayed based on specific criteria?

    We are not saying you cannot x-post, but you MUST share the link to the x-post here...and seeing as most forums have this same requirement, it would be best if you let them know you posted here, too
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  9. #9
    Registered User
    Join Date
    01-31-2015
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    91

    Re: Formula to Format how time (hh:mm:ss) is displayed based on specific criteria?

    Hi FDibbins

    I did that right after my last post here, apologies again.

  10. #10
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Formula to Format how time (hh:mm:ss) is displayed based on specific criteria?

    Thank you Fluff13 - this has given me a start.
    You're welcome & thanks for the feedback.

+ 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. Replies: 3
    Last Post: 09-24-2019, 04:29 PM
  2. Format a specific CELL based on TIME
    By JediTrader in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-25-2019, 12:10 PM
  3. [SOLVED] time sheet help, format TIME and formula based on the actual time entered.
    By bh mng in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 12-06-2016, 01:10 PM
  4. [SOLVED] Read Or Return Time In Displayed Format
    By OzTrekker in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-25-2016, 05:50 PM
  5. count the number of occurance based on time and date and specific criteria
    By stoey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-02-2014, 03:34 PM
  6. Use the Displayed value in a Specific Formula
    By Enigmafish14 in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 11-28-2013, 12:25 AM
  7. Need to sort data based on criteria, and specific format
    By wparker80 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-05-2012, 05:16 PM

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