+ Reply to Thread
Results 1 to 3 of 3

modification for the code

  1. #1
    srinivasan
    Guest

    modification for the code

    Hi
    The following code will show result in percentage with left aligned(TEXT) in
    excel. My requirement is that the result should be right aligned (in number
    format)
    with the same percentage symbol along with the result. ( rather than
    text with left aligned). Otherwise the code works fine and no change is
    required.

    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

    I am repeatedly asking for help but no avail. Will any one familiar with
    this area would kindly help me. As I am not familar with the VBA and got this
    thro one of my friend I am helpless.


  2. #2
    Registered User
    Join Date
    08-11-2005
    Location
    Netherlands Waddinxveen
    Posts
    81
    Although your code works fine it is also a bit ugly

    but you should look at:
    HorizontalAlignment = xlRight

    Tip: if you start the macro editor and record a macro doing what yopu want to achieve and stop it the vba code of this macro is stored in a new module.

  3. #3
    Bob Phillips
    Guest

    Re: modification for the code

    Just change this line

    CAGR = Format(v, "00.00%")

    to

    CAGR = v

    and format the cell in Excel. A UDF cannot format the cell, just return an
    answer.

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "srinivasan" <[email protected]> wrote in message
    news:[email protected]...
    > Hi
    > The following code will show result in percentage with left aligned(TEXT)

    in
    > excel. My requirement is that the result should be right aligned (in

    number
    > format)
    > with the same percentage symbol along with the result. ( rather than
    > text with left aligned). Otherwise the code works fine and no change is
    > required.
    >
    > 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
    >
    > I am repeatedly asking for help but no avail. Will any one familiar with
    > this area would kindly help me. As I am not familar with the VBA and got

    this
    > thro one of my friend I am helpless.
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1