Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Feb 2006
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to make a percent in VBA (2003)

    I am writing an Excel program, and there is a column that divides two numbers to get a percentage. For example a / b may come out to 0.807657. I would like to have the code after figuring out the number, format the cell the number 0.807657 to 80.7. Or if it comes out to 1.04355, format it to 100.0. Can anyone please help me.

    Thanks,
    Chris

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: How to make a percent in VBA (2003)

    If you want it to look like 80.7%, you can use code like this:
    <code>
    Range("A1").NumberFormat = "0.0%"
    </code>
    The % in the format implicitly performs the necessary multiplication by 100. If you want it to look like 80.7, you'd have to do the multiplication yourself
    <code>
    Range("A1") = a / b * 100
    Range("A1").NumberFormat = "0.0"
    </code>
    Why should 1.04355 be displayed as 100.0?

  3. #3
    Lounger
    Join Date
    Feb 2006
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to make a percent in VBA (2003)

    Thanks Hans for your help.

    Chris

Posting Permissions

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