request code for right align and percentage

G

Guest

Dear friends,
The following code will show result in percentage with left aligned(TEXT) in
excel. My requirement is that the result should be in number format right
aligned with the same percentage symbol along with the result. ( rather than
text with left aligned)

Public Function CAGR(FirstValue, LastValue)
Dim fv, lv, v As Double
Set r = Application.Range(FirstValue, LastValue)
Count = (Application.Range(FirstValue, LastValue).Count - 1)
CAGR = FirstValue
v = Application.WorksheetFunction.Rate(Count, 0, -(FirstValue), LastValue)
CAGR = Format(v, "00.00%")
End Function

Will any one guide me with the correct code for my requirement with required
modification.
 
G

Guest

Hi,

Range("a1")=CAGR(....) will be right-aligned as percentage

What are the values of FirstValue and LastValue as the logic doesn't appear
to be correct regarding Range.
 
G

Guest

Hi Toppers,

Thank you for your immediate response. Range is (First Value :Last
Value)which represents pv for present value and fv for future value of rate
function.
The correction to the code for right alignment with percentage symbol next
to the value may please be guided.
 
G

Guest

Hi,
Why use a user function when you can simply DO:


CAGR= Application.WorksheetFunction.Rate(Count, 0, -(FirstValue), LastValue)

And sssign CAGR to wherever in your code:

e.g. Range("B3")=Format(CAGR,"00.00%")
 
G

Guest

Hi Toppers,

Again thank you for your response. I am new to VBA and just entering. Kindly
give me the full code according to your advice. I can"t understand
Range("B3"). Once again Thank you in advance.
 
G

Guest

Hi,
Range("b3") means you want to place your answer in Cell B3. Where do
you want the result of your calculation to go?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top