+ Reply to Thread
Results 1 to 10 of 10

Convert a Column with Text and Numbers to a Duration Cell in h:mm

  1. #1
    Forum Contributor
    Join Date
    07-22-2013
    Location
    london
    MS-Off Ver
    Excel 2013
    Posts
    133

    Convert a Column with Text and Numbers to a Duration Cell in h:mm

    To keep it short and sweet, we have a column like this:

    5 mins
    1 min
    1 hr, 45 mins
    3 hrs
    1 hr
    6 hrs, 1 min

    and we want the output in h:mm duration format, like:

    0:05
    0:01
    1:45
    3:00
    1:00
    6:01

    How do we do it with a formula?

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Convert a Column with Text and Numbers to a Duration Cell in h:mm

    B1 =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(IF(ISERROR(FIND("min",IF(ISERROR(FIND("hr",C1,1)),"0 hr, " &A1,A1))),IF(ISERROR(FIND("hr",C1,1)),"0 hr, " &A1,A1)&", 0 min",IF(ISERROR(FIND("hr",C1,1)),"0 hr, " &A1,A1)),"min",""),"s","")," hr, ",":")*1

    Format custom hh:mm
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Convert a Column with Text and Numbers to a Duration Cell in h:mm

    Sorrry, sucuri firewall did not let me write the code, so find it in file attach.
    Attached Images Attached Images
    Attached Files Attached Files
    Quang PT

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Convert a Column with Text and Numbers to a Duration Cell in h:mm

    OK, so here it is:

    =TIMEVALUE(IF(IFERROR(FIND(":",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE([@String]," ",""),"min",""),"hr",""),"s",""),",",":")),0)=0,"0:"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE([@String]," ",""),"min",""),"hr",""),"s",""),",",":"),SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE([@String]," ",""),"min",""),"hr",""),"s",""),",",":")))

    Yeah, right!

    See the attached spreadsheet to understand how I got there.

    Colum A is String. This is the string as copied from your post.

    Column B is String 1 which basically takes out min and mins, hr and hrs and substitutes a colon for the comma so the resulting string looks almost like a string for time.

    Column C is String 2 which is either zero if string 1 does not have a colon or zero or some other number if String 1 does have a colon. The find command is one way to test if a string has a certain substring.

    Column D is String 3 the formula here puts "0:" in front of String 1 when it needs it (in other words only minutes are in the original string).

    Column E is Time which is the TIMEVALUE of string 3.

    Colum F is the same formula as column E except that the pieces are successively substituted back until everything is expressed only in terms of Column A (The original string)
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  5. #5
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Convert a Column with Text and Numbers to a Duration Cell in h:mm

    Try

    =SUMPRODUCT(TEXT(MID(0&A2,FIND({"h","m"},0&A2&"hm")-2,2),"0;;;\0")/{24,1440})
    Attached Files Attached Files

  6. #6
    Valued Forum Contributor
    Join Date
    11-22-2014
    Location
    Arizona, USA
    MS-Off Ver
    Office 365
    Posts
    973

    Re: Convert a Column with Text and Numbers to a Duration Cell in h:mm

    While I like a few of the solutions - this is likely what I would utilize as a ripper value off of text... This assumes that you are consistent in formatting if there is no hour then just the minute is placed and if there is an hour it is written followed by a comma... this comma is the guide to the formula below... with or without it dictates if there are hours to be evaluated... so if your format is that in which you shared then this should work great.

    Please Login or Register  to view this content.
    -If you think you are done, Start over - ELeGault

  7. #7
    Forum Contributor
    Join Date
    07-22-2013
    Location
    london
    MS-Off Ver
    Excel 2013
    Posts
    133

    Re: Convert a Column with Text and Numbers to a Duration Cell in h:mm

    Thanks mehmetcik, but I'm getting this instead of the desired output:

    00:05
    00:01
    00:01
    00:03
    00:01
    00:06

    --

    Thanks bebo021999, your formula works like a charm..

    Here is it again:
    =MID("00hr00"&SUBSTITUTE(SUBSTITUTE(A1," ",""),",","00")&"000m",IFERROR(SEARCH("hr","00hr00"&SUBSTITUTE(SUBSTITUTE(A1," ",""),",","00")&"000m",SEARCH("hr","00hr00"&SUBSTITUTE(SUBSTITUTE(A1," ",""),",","00")&"000m")+1),SEARCH("hr","00hr00"&SUBSTITUTE(SUBSTITUTE(A1," ",""),",","00")&"000m"))-2,2)/24+MID("00hr00"&SUBSTITUTE(SUBSTITUTE(A1," ",""),",","00")&"000m",SEARCH("m","00hr00"&SUBSTITUTE(SUBSTITUTE(A1," ",""),",","00")&"000m")-3,3)/1440
    --

    Thanks dflak for the detailed reply.
    Close enough, but getting this instead of the desired output:

    0:05
    0:01
    1:45
    0:03
    0:01
    6:01

    (4 and 5 are wrong, as they're showing as minutes.)


    --

    Thanks Bo_Ry, close enough but the 3rd sample is giving 1:05 instead of 1:45
    Last edited by nicoan; 11-26-2021 at 02:08 PM.

  8. #8
    Valued Forum Contributor
    Join Date
    11-22-2014
    Location
    Arizona, USA
    MS-Off Ver
    Office 365
    Posts
    973

    Re: Convert a Column with Text and Numbers to a Duration Cell in h:mm

    If your format stays like your example... this should be golden for you...

    Please Login or Register  to view this content.

  9. #9
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Convert a Column with Text and Numbers to a Duration Cell in h:mm

    Try again

    =SUMPRODUCT(TEXT(MID(0&A2,FIND({"h","m"},0&A2&"hm")-3,3),"0;;;\0")/{24,1440})
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    07-22-2013
    Location
    london
    MS-Off Ver
    Excel 2013
    Posts
    133

    Re: Convert a Column with Text and Numbers to a Duration Cell in h:mm

    Quote Originally Posted by Bo_Ry View Post
    Try again

    =SUMPRODUCT(TEXT(MID(0&A2,FIND({"h","m"},0&A2&"hm")-3,3),"0;;;\0")/{24,1440})
    Perfect..

    I don't understand that kind of sorcery, but it's the shortest formula, and it works perfectly.
    Thanks a million!

+ 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. Convert Excel text to time duration
    By KrazyKasper in forum Excel General
    Replies: 4
    Last Post: 06-08-2019, 01:15 PM
  2. [SOLVED] Convert column of numbers to text
    By dchubbock in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-26-2017, 07:50 PM
  3. [SOLVED] How to convert all data in column from text to numbers
    By meechie in forum Excel General
    Replies: 2
    Last Post: 08-20-2012, 02:23 PM
  4. Convert Text to Duration
    By brettdowden in forum Excel General
    Replies: 2
    Last Post: 03-08-2012, 04:51 PM
  5. Convert Duration to Numbers of Months
    By VICTOR5 in forum Excel General
    Replies: 7
    Last Post: 06-13-2011, 07:31 AM
  6. Convert cell containing numbers as text into a sum...
    By Stevie-B in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-10-2008, 11:52 AM
  7. [SOLVED] HOW CAN I CONVERT NUMBERS INTO TEXT IN A PARTICULAR CELL.
    By Jaya in forum Excel General
    Replies: 3
    Last Post: 03-05-2005, 01:10 PM

Tags for this Thread

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