+ Reply to Thread
Results 1 to 15 of 15

extract time-values from variable text

  1. #1
    Registered User
    Join Date
    01-27-2012
    Location
    Blankenberge, Belgium
    MS-Off Ver
    Excel 2003
    Posts
    28

    extract time-values from variable text

    Hereby the cell:

    "From 07/09/11 till 13/06/12
    Ma Gesloten
    Di Gesloten
    Wo Open from 14:00 till 16:55
    Do Gesloten
    Vr Gesloten
    Za Gesloten
    Zo Gesloten
    Meer uitleg : Geen lessen tijdens de schoolvakanties
    "

    I need to create a macro/script to extract 14:00 and 16:55 in above text, these are two timevalues (from and till). They need to be extracted each to a new cell in the same format HH:MM. Text is variable.
    I have a variable column with values, so the macro/script needs to applie to a whole colum (range x:x)
    Please advise!
    Thx!
    Last edited by WilliamV; 02-09-2012 at 11:30 AM.

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: extract time-values from variable text

    Hello,

    is the text all in one cell? If so, you can extract the start time with

    =TIMEVALUE(MID(A1,FIND(":",A1)-2,5))

    and the end time with

    =TIMEVALUE(MID(A1,FIND(":",A1,FIND(":",A1)+1)-2,5))

    In case the text does not contain two time values, you would need to use error trapping with IFERROR() or similar.

    cheers,

  3. #3
    Registered User
    Join Date
    01-27-2012
    Location
    Blankenberge, Belgium
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: extract time-values from variable text

    Thank you for the quick follow-up.
    Yes, all of it is in one cell.
    Your code produces an error?
    Can you explain a bit further about the error trapping? And how do i put this in a macro/function in VB?
    Thank you.
    Last edited by WilliamV; 01-27-2012 at 09:21 AM.

  4. #4
    Registered User
    Join Date
    01-27-2012
    Location
    Blankenberge, Belgium
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: extract time-values from variable text


  5. #5
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: extract time-values from variable text

    Your code produces an error?
    Can you specify that?

    See attached.

    Why would you want to use VBA if a formula does it nicely?
    Attached Files Attached Files

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: extract time-values from variable text

    Hi William,

    I keep trying to find some fault with teylyn's formulas and rarely (as in never) do. You will need to adjust her example formulas by changing A1 to the cell you have your text in. Her formula looks for the first colon and second colon in the text and uses them to find the start and end times. If you were to have a colon before them, her formula won't work.

    If you supply a sample workbook with what doesn't work, I'm sure we (mostly teylyn) can find exactly why.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  7. #7
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: extract time-values from variable text

    Your code produces an error?
    Can you explain a bit further about the error trapping?
    On behalf of Teylyn
    If there are no time values to be found in your string then the formula will return a #VALUE! error.
    Given that you are using 2003 then the error trapping is handled like this:=

    =IF(ISERROR("formula"),"","formula")
    or to avoid blank cells returning an error
    =IF(A2="","","formula")

    [EDIT]
    To address Marvins' concerns about colons preceding the time I've added a formula to minimise the risk of errors
    e.g.
    Please Login or Register  to view this content.
    Attachment updated
    Attached Files Attached Files
    Last edited by Marcol; 01-29-2012 at 05:18 AM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  8. #8
    Registered User
    Join Date
    01-27-2012
    Location
    Blankenberge, Belgium
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: extract time-values from variable text

    teylin, MarvinP & Marcol, thank you very much for helping me out.

    Regarding
    the code producing an error:
    apparently this was due to a language-conflict in excel, i use the dutch version, is this possible? When trying your examples though everything works fine.

    Regarding
    Why would you want to use VBA if a formula does it nicely?
    i refer to another post i submitted.
    As you can see i call up data from another xls-file to populate data in a new xls-file. This i do by using VB-script to automate the process for the end-user.

    So my question remains how to put all of this in VB-script with error-handling as mentioned above by teylin and Marcol.
    Thank you all in advance for time and efforts!

  9. #9
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: extract time-values from variable text

    You might need to change the comma "," seperators to semi-colons ";" in the formulae.

  10. #10
    Registered User
    Join Date
    01-27-2012
    Location
    Blankenberge, Belgium
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: extract time-values from variable text

    Can you help further in putting the formula into vbscript?
    Thx.

  11. #11
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: extract time-values from variable text

    In excel we use VBA.

    I think you are using a flemish version of Excel ?
    to split the time in cell A1 to cell B1 and C1:

    Please Login or Register  to view this content.



  12. #12
    Registered User
    Join Date
    01-27-2012
    Location
    Blankenberge, Belgium
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: extract time-values from variable text

    I'm confused: don't i need to specify the cells in this code?

    If the range would be the whole B-column (B:B) and i want to put out to columns B and C ?
    Please advise.
    Thank you.

  13. #13
    Registered User
    Join Date
    01-27-2012
    Location
    Blankenberge, Belgium
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: extract time-values from variable text

    I'm confused: don't i need to specify the cells in this code?

    If the range would be the whole B-column (B:B) and i want to put out to columns B and C ?
    Please advise.
    Thank you.

  14. #14
    Registered User
    Join Date
    01-27-2012
    Location
    Blankenberge, Belgium
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: extract time-values from variable text

    Can you please help me further on this one?
    How do i set the range the code must apply to? If dfata is in cell G and need to be exported as ??:?? to cell G and H?
    Thank you in advance.

  15. #15
    Registered User
    Join Date
    01-27-2012
    Location
    Blankenberge, Belgium
    MS-Off Ver
    Excel 2003
    Posts
    28

    Re: extract time-values from variable text

    As nobody could help me with the specification of the last mentioned VBA, i decided to apply the formula's in my worksheetr. This works well, so to everyone that helped sove my issues, thank you!

+ 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