Consulting

Results 1 to 4 of 4

Thread: TimeSerial does not reflect Windows Regional Settings

  1. #1
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location

    TimeSerial does not reflect Windows Regional Settings

    I'm trying to make a workbook respond to changes in the Windows Regional Settings.

    According to what I've read, this is the way to enter currency, date, and times.

    Option Explicit
    Sub Macro1()
        Worksheets("Sheet1").Columns(1).Delete
        Worksheets("Sheet1").Range("a1").Value = CCur(-12341234.45)
        Worksheets("Sheet1").Range("a2").Value = DateSerial(2014, 10, 20)
        Worksheets("Sheet1").Range("a3").Value = TimeSerial(10, 10, 15)
    End Sub
    The Currency and the Date have the Number Format = 'Currency' and 'Date' but the Time has a Number Format = 'Custom'

    Currency and Date respond to changes in WRS, but since Time is 'Custom' it does not. If I manually apply the 'Time' format, then it does respond.

    Can anyone suggest a correction or workaround?

    Thanks
    Attached Images Attached Images
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Sub Macro1()
        Worksheets("Sheet1").Columns(1).Delete
        Worksheets("Sheet1").Range("a1").Value = CCur(-12341234.45)
        Worksheets("Sheet1").Range("a2").Value = DateSerial(2014, 10, 20)
        Worksheets("Sheet1").Range("a3").Value = TimeSerial(10, 10, 15) / 1
        Worksheets("Sheet1").Range("a3").NumberFormat = "hh:mm:ss"
    End Sub

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    @snb -- that moved me a little in a different direction. SinceCCur and DateSerial didn't require any NumberFormat-ing, I was trying to figure out a similar way for TimeSerial. Just would have made things a little simpler over all.

    Without the Locale ID [$-F400] it was not reliable and seemed to depend on the WRS setting when the data was entered. But so far (fingers crossed) this seems to be working

    Option Explicit
    'http://office.microsoft.com/en-us/excel-help/creating-international-number-formats-HA001034635.aspx
    Sub Macro1()
        Worksheets("Sheet1").Columns(1).Delete
        Worksheets("Sheet1").Range("a1").Value = CCur(-12341234.45)
        Worksheets("Sheet1").Range("a2").Value = DateSerial(2014, 10, 20)
        Worksheets("Sheet1").Range("a3").Value = TimeSerial(20, 10, 15)
        Worksheets("Sheet1").Range("a3").NumberFormatLocal = "[$-F400]h:mm:ss AM/PM"
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Since you are making it a fixed format why don't you use ?

    Worksheets("Sheet1").Range("a3").NumberFormat = "[$-F400]h:mm:ss AM/PM"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •