VBA automatically gets fractions

Source: Internet
Author: User

'divides a positive number by Y to return an integer or fractionFunctionRFs (ByValX as Integer) as String    Ifx =0  ThenRFs=0        Exit Function    End If    DimDiv_result, Div_remain, y, I as Integery=144Div_result= x \y Div_remain= XModyIfDiv_remain =0  ThenRFs= x/yExit Function    Else        DimZ as Integer        IfDiv_remain > Y ThenZ=yElseZ=Div_remainEnd If                 fori = Z to 2 Step-1            IfDiv_remainModi =0  andYModi =0  Then                IfDiv_result >0  ThenRFs= Div_result &" + "& div_remain/i &"/"& Y/IElseRFs= div_remain/i &"/"& Y/IEnd If                Exit Function            End If        NextIIfDiv_result >0  ThenRFs= Div_result &" + "& Div_remain &"/"&yElseRFs= Div_remain &"/"&yEnd If    End IfEnd Function

can be called directly in the Excel macro in the VBA language, such as 290 will get 2 + 1/72

VBA automatically gets fractions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.