Consulting

Results 1 to 2 of 2

Thread: Can you Format as fraction in VBA -- Format(123.456, "# ??/16")

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

    Can you Format as fraction in VBA -- Format(123.456, "# ??/16")

    This is an extract of larger project

    Simplified it to just experiment in immediate window to try and get it to work

    I put 123.456 in A1, and formatted it using the Format, Number, Fraction, As Sixteenths

    Displays correctly on worksheet as 123 7/16

    When I try to Format() it internally as part of a string, I get 123 ??/16

    ?activecell.NumberFormat
    # ??/16
    
    ?format(123.456, "# ??/16")
    123 ??/16
    Does Format() work with fraction formats?
    ---------------------------------------------------------------------------------------------------------------------

    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
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Found an answer - Format () for fractions doesn't work, but Application.WorksheetFunction.Text () does

    ?application.WorksheetFunction.Text(123.456, "# ??/16")
    123  7/16
    ---------------------------------------------------------------------------------------------------------------------

    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

Posting Permissions

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