+ Reply to Thread
Results 1 to 3 of 3

VBA Convesion of Decimal Time Values to Formatted Text

  1. #1
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    335

    VBA Convesion of Decimal Time Values to Formatted Text

    I am using these two lines of code of populate a couple columns in my database with time values.
    Please Login or Register  to view this content.
    They are being populated as decimal values, rather than the h:mm am/pm format preferred.

    Since I will be using these values in strings at a later time, what would I need to add to convert these decimal values to a textual format of h:mm am/pm.

    Thanks in advance.

  2. #2
    Forum Moderator Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    28,343

    Re: VBA Convesion of Decimal Time Values to Formatted Text

    I suggest you don't change the values to strings in the worksheet, just format columns F & G as h:mm am/pm

    Then when you want to read the value as a string (presumably in the VBE) use

    stMyString = Format(Range("A1"), "hh:mm am/pm")
    Richard Buttrey

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    335

    Re: VBA Convesion of Decimal Time Values to Formatted Text

    Thank you Richard for your suggestion ...

    The data source is now formatted at a time (hh:mm am/pm) rather than it's decimal equivalent.
    I'm having great difficulty however with integrating the "format" into my vba formula.

    Please Login or Register  to view this content.
    eg staff.range ("D16") = 8:00 AM, staff.range ("D16") = 8:00 AM, staff.range ("E16") = 1:00 PM,Result for range("K5") "8:00A - 1:00P"

    I'm receiving a Type mismatch error.

    Jenn

+ 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