Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Can you add cell formatting into a function in Microsoft Excel Visual Basic?
I have this simple function:
Public Function PC(Numberone, numbertwo)
PC = (Numberone / numbertwo - 1)
Selection.NumberFormat = "0.0%"
End Function
Now, the selection formatting thing there doesn't work - the function only presents the number as a decimal, whereas i want it in a percentage. obviously i can format it like this separately, but it'd be much more convenient to build it into the function!
any ideas?
thanks!
1 Answer
- 1 decade ago
It is possible to have formatting in Excel VBA.
But what is not clear for me is you haven't assign the PC value back to one of the cell first and you simply compute the value and apply the formatting on your case.
Try this
PC = (Numberone / numbertwo - 1)
Range("A1").value = PC
Range("A1").NumberFormat = "0.0%"
Another advise while dividing numbers it will be good for you to test the denominator is not zero first