+ Reply to Thread
Results 1 to 5 of 5

Convert irregular text into hours

  1. #1
    Registered User
    Join Date
    09-09-2016
    Location
    Thailand
    MS-Off Ver
    2015
    Posts
    4

    Convert irregular text into hours

    Hi experts

    I've got the following data output to work with.

    ---------------------

    30 days 12 hours 18 minutes
    1 day 1 hour 1 minute
    45 minutes
    6 hours 1 minute

    ---------------------

    My goal is to convert this data into decimal hours.

    As you can see, the data is irregular, sometimes there's only 1 number (i.e. NOT 06 hours).
    Also the letters have different lenghth (day, days etc.)

    I've tried to split the data up into cells for further processing but I'm getting the following problem

    30
    1
    45
    6

    If there are no days, the hours jump into collum A and if there are no days and hours, the minutes jump in collum A.

    I've tried to read out the cell with

    =LEFT([@[*Time in Online Sessions]];2)*24

    That works well, but how to handle the middle and the right part, if the length of numbers and text are varying?



    Sorry for my bad english and thanks fpr your help.
    Last edited by thairicci; 09-10-2016 at 01:57 AM.

  2. #2
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,925

    Re: Convert irregular text into hours

    Try this ...

    =IFERROR(LEFT(A1,SEARCH("day",A1)-1),0)*24+IFERROR(LOOKUP(24,--MID(A1,SEARCH("hour",A1)-{1,2,3},{1,2,3})),0)+IFERROR(LOOKUP(60,--MID(A1,SEARCH("minute",A1)-{1,2,3},{1,2,3})),0)/60

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Convert irregular text into hours

    I know one big monster formula can be constructed from all this, but this is easier to understand/analyze.

    Assuming the first value is in A2:

    B2: =IFERROR(LEFT(" "&$A2, SEARCH(B$1, " "&$A2)-1)+0, "")
    C2: =IFERROR(MID(" "&$A2, SEARCH(C$1, " "&$A2)-3, 2)+0, "")
    D2: =IFERROR(MID($A2, SEARCH(D$1, $A2)-3, 2)+0, "")

    F2: =(N(B2)*24)
    G2: =N(C2)
    H2: =N(D2)/60
    I2: =SUM(F2:H2)

    Data Range
    A
    B
    C
    D
    E
    F
    G
    H
    I
    1
    Text
    Day
    Hour
    Minute
    DayHrs
    Hrs
    MinHrs
    Dec.Hrs
    2
    30 days 12 hours 18 minutes
    30
    12
    18
    720
    12
    0.30
    732.30
    3
    1 day 1 hour 1 minute
    1
    1
    1
    24
    1
    0.02
    25.02
    4
    45 minutes
    45
    0
    0
    0.75
    0.75
    5
    6 hours 1 minute
    6
    1
    0
    6
    0.02
    6.02
    6
    16 hours
    16
    0
    16
    0.00
    16.00
    7
    1 hour 12 minutes
    1
    12
    0
    1
    0.20
    1.20
    8
    1 day 22 minutes
    1
    22
    24
    0
    0.37
    24.37
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    09-09-2016
    Location
    Thailand
    MS-Off Ver
    2015
    Posts
    4

    Re: Convert irregular text into hours

    you're awesome!

    Thanks a lot to both of you!!!
    Last edited by thairicci; 09-10-2016 at 02:05 AM.

  5. #5
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

    Re: Convert irregular text into hours

    Please Login or Register  to view this content.
    try this and copy towards down
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

+ 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. [SOLVED] Convert text time into hours
    By Justmegan93 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-11-2016, 10:06 AM
  2. [SOLVED] Function or macro to convert string with weeks, days, hours, minutes to Hours
    By kknb0800 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-23-2012, 11:35 AM
  3. Convert text to hours/timestamp
    By Daniel86 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-12-2012, 06:06 PM
  4. Irregular hours
    By Fedde in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-05-2007, 07:34 PM
  5. calculating irregular hours
    By Fedde in forum Excel General
    Replies: 1
    Last Post: 01-05-2007, 04:12 AM
  6. Replies: 5
    Last Post: 06-22-2006, 10:10 PM
  7. [SOLVED] Convert irregular data to monthly equivalent?
    By RBW in forum Excel General
    Replies: 3
    Last Post: 04-02-2006, 03:40 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