Hi. How do I add code that will convert below code into fractions? Thank you
Please Login or Register to view this content.
Hi. How do I add code that will convert below code into fractions? Thank you
Please Login or Register to view this content.
Format the number as a fraction: Format > Cells > Number tab, choose Fraction in the Category box?
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
I could format the cell but is there a way I could do it with VBA?
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: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.Please Login or Register to view this content.
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.
Originally Posted by shg
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks