Results 1 to 16 of 16

Convert Text :> Time... Using VBA

Threaded View

  1. #14
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: Convert Text :> Time... Using VBA

    Code for UDF DayAndTime. Format cells for [hh]:mm:ss.
    Function DayAndTime(IP As Range)
    Dim M
    Dim T As Integer, d_ays As Integer, hrs As Integer, mns As Integer, scs As Integer
    
    M = Split(IP.Value, " ")
    For T = 0 To UBound(M)
        If InStr(1, M(T), "mos") > 0 Then
        d_ays = 30 * (Replace(M(T), "mos", ""))
        ElseIf InStr(1, M(T), "w") > 0 Then
        d_ays = d_ays + 7 * (Replace(M(T), "w", ""))
        ElseIf InStr(1, M(T), "d") > 0 Then
        d_ays = d_ays + (Replace(M(T), "d", ""))
        ElseIf InStr(1, M(T), "h") > 0 Then
        hrs = 0 + (Replace(M(T), "h", ""))
        ElseIf InStr(1, M(T), "m") > 0 Then
        mns = 0 + (Replace(M(T), "m", ""))
        ElseIf InStr(1, M(T), "s") > 0 Then
        scs = 0 + (Replace(M(T), "s", ""))
        End If
    
    Next T
        
        DayAndTime = TimeSerial((d_ays * 24) + hrs, mns, scs)
        
    End Function
    Attached Files Attached Files
    Last edited by kvsrinivasamurthy; 04-12-2021 at 06:09 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Convert Text Field with time > 24hours to time
    By Viema in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-29-2020, 07:26 AM
  2. [SOLVED] Convert text time to decimal time
    By HappierThan in forum Excel General
    Replies: 5
    Last Post: 06-13-2020, 12:51 AM
  3. Convert Text Time From A Userform Textbox to A Time Value
    By Jenn68 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-21-2019, 09:53 PM
  4. Replies: 15
    Last Post: 08-23-2017, 03:32 PM
  5. Excel convert Text time formatted 10h 58m to time so I can sum together
    By slinka in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 02-04-2016, 10:17 AM
  6. Time stored as text. How can I convert to data and time?
    By matthewbutterworth in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-07-2013, 10:19 AM
  7. [SOLVED] convert time imported as text to time format for calculations
    By batfish in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-27-2005, 07:05 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