+ Reply to Thread
Results 1 to 8 of 8

Excel If-Else formula to capture ''hour“ and ”min" across an excel row

  1. #1
    Registered User
    Join Date
    01-13-2021
    Location
    Mumbai
    MS-Off Ver
    MS Office Standard 2010
    Posts
    5

    Excel If-Else formula to capture ''hour“ and ”min" across an excel row

    I have a row of "h min" values (eg:2h 15min) across a row. I need to capture the 'hour' and 'min' separately for which I'm using "=LEFT(B2,(FIND(" ",B2,1)-1))" and "=MID(B2,FIND(" ",B2)+1,256)" in separate cells, using the space separator to identify them seperately.

    The problem is when there is only either one value, i.e. only hour or only minute (eg. "2h" or "20min") in which case I get an error. How should I re-code both my LEFT and MID formula with IF-ELSE to ensure it still captures the hour/minute where it's present and gives a blank where it's not present.

    Many thanks.
    Attached Files Attached Files
    Last edited by Mithun.Uchil; 01-14-2021 at 02:39 AM.

  2. #2
    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,929

    Re: Excel If-Else formula to capture ''hour“ and ”min" across an excel row

    To best describe or illustrate your problem you would be better off attaching a dummy workbook. The workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    To attach a file to your post,
    click advanced (next to quick post),
    scroll down until you see "manage file",
    click that and select "add files" (top right corner).
    click "select files" find your file, click "open" click "upload" click 'done" bottom right. click "submit reply"

    Once the upload is completed the file name will appear below the input boxes in this window.
    You can then close the window to return to the new post screen.
    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

  3. #3
    Registered User
    Join Date
    01-13-2021
    Location
    Mumbai
    MS-Off Ver
    MS Office Standard 2010
    Posts
    5

    Re: Excel If-Else formula to capture ''hour“ and ”min" across an excel row

    Thanks. Attached a workbook for reference.

  4. #4
    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,929

    Re: Excel If-Else formula to capture ''hour“ and ”min" across an excel row

    Try these...
    hour =IFERROR(LEFT(B2,SEARCH("h",B2)),"")
    min =IFERROR(MID(B2,FIND(" ",B2)+1,99),"")

  5. #5
    Registered User
    Join Date
    01-13-2021
    Location
    Mumbai
    MS-Off Ver
    MS Office Standard 2010
    Posts
    5

    Re: Excel If-Else formula to capture ''hour“ and ”min" across an excel row

    Hi FDibbins,

    Thanks, this worked for the hour, but does not work where only 'min' is there since there is no space before 'min' in this case, hence the FIND " " does not work there. Any roundabout for this??

    Updated my excel with your formula which works for the hour but not the minute.

    Many, many thanks again from again from a newbie here.
    Attached Files Attached Files

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

    Re: Excel If-Else formula to capture ''hour“ and ”min" across an excel row

    B3:
    =TRIM(LEFT(SUBSTITUTE(SUBSTITUTE(IF(ISNUMBER(SEARCH("h",B2)),"","h")&B2&IF(ISNUMBER(SEARCH("min",B2)),"","min"),"h",REPT(" ",20)),"min",REPT(" ",20)),20))&IF(ISNUMBER(SEARCH("h",B2)),"h","")

    B4:
    =TRIM(MID(SUBSTITUTE(SUBSTITUTE(IF(ISNUMBER(SEARCH("h",B2)),"","h")&B2&IF(ISNUMBER(SEARCH("min",B2)),"","min"),"h",REPT(" ",20)),"min",REPT(" ",20)),20,20))&IF(ISNUMBER(SEARCH("min",B2)),"min","")
    Attached Files Attached Files
    Quang PT

  7. #7
    Registered User
    Join Date
    01-13-2021
    Location
    Mumbai
    MS-Off Ver
    MS Office Standard 2010
    Posts
    5

    Re: Excel If-Else formula to capture ''hour“ and ”min" across an excel row

    Thanks!! This one works bebo021999

  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,929

    Re: Excel If-Else formula to capture ''hour“ and ”min" across an excel row

    Try this for the MIN part...
    =IFERROR(MID(B2,FIND(" ",B2)+1,99),IF(AND(ISERROR(FIND(" ",B2)),NOT(ISERROR(FIND("min",B2)))),B2,""))

+ 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] Excel formula to capture invoice number
    By sunboy in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-19-2020, 01:54 PM
  2. Capture Value from a Cell only once at a specific hour.
    By EEEHHH in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-23-2019, 01:55 PM
  3. Replies: 3
    Last Post: 04-11-2018, 07:13 AM
  4. Replies: 1
    Last Post: 04-10-2018, 11:40 AM
  5. [SOLVED] Require a formula to display "Preparation Time" if half hour slot is available
    By john dalton in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-10-2014, 04:43 AM
  6. [SOLVED] Combine "=IF" and "=HOUR" statement for cell formula
    By chriswhite1982 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-19-2013, 02:42 PM
  7. Replies: 0
    Last Post: 09-27-2012, 02:25 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