+ Reply to Thread
Results 1 to 5 of 5

decimal to fraction

  1. #1
    Forum Contributor
    Join Date
    02-18-2013
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    112

    decimal to fraction

    Hi. How do I add code that will convert below code into fractions? Thank you


    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    03-27-2015
    Location
    los angeles
    MS-Off Ver
    2013
    Posts
    40

    Re: decimal to fraction

    Format the number as a fraction: Format > Cells > Number tab, choose Fraction in the Category box?

  3. #3
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: decimal to fraction

    Don't you need to format as fraction the cell where is = koshent(numerator, denominator)
    BTW
    you could use


    Please Login or Register  to view this content.
    - Battle without fear gives no glory - Just try

  4. #4
    Forum Contributor
    Join Date
    02-18-2013
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    112

    Re: decimal to fraction

    I could format the cell but is there a way I could do it with VBA?

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: decimal to fraction

    I'm sure there is a way to do it with VBA. Perhaps if you explained the overall context and why you want to do it in VBA.

    One thing will be sure, a UDF cannot change the format of the cell it resides in. If the UDF result will not be needed in other calculations, you could dimension the UDF to return a string, then use text manipulation functions to return a text string:
    Please Login or Register  to view this content.
    The problem that will usually come from this approach is that the result of koshent is a text string, not a real number, and any calculations that depend on the result of koshent will need to convert the text string into a number.

    If you would like, you can use a separate VBA Sub procedure to format the cell as fraction ("0 0/0") using the .numberformat property of the cell. I'm not sure why this would be an advantage, though.

    I think we will need a broader context to understand why you want to do this in VBA. IMO, the simplest approach, like with built in functions, is to have the UDF return a double like you have it, then use number formatting like amorshc and PCI suggested.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Converting decimal into a fraction via vba
    By pooky in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-28-2013, 08:32 PM
  2. Convert fraction to a decimal
    By Dillons Grandpa in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 02-24-2013, 12:49 PM
  3. [SOLVED] Fraction to Decimal
    By Michael D in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 02-13-2013, 03:21 PM
  4. Decimal To Fraction (Inches)
    By mgaworecki in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-07-2008, 11:47 AM
  5. leave the decimal fraction
    By Darrel in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-06-2006, 02:00 AM

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