+ Reply to Thread
Results 1 to 3 of 3

Looking for a UDF to calculate for a practical question

  1. #1
    Forum Contributor
    Join Date
    01-16-2014
    Location
    London
    MS-Off Ver
    Excel 2003 Excel 2010
    Posts
    189

    Looking for a UDF to calculate for a practical question

    Dear all, I have a practical question to solve using a UDF. I have little knowledge about VBA, so really look for your help.

    The question is: to calculate the percentage of years that a company had positive dividend growth. So the UDF will be something like: DivGrowth(Range), here the range gives the history of annual dividends paid by a company over the past years.

    Please see the example attached here.

    Column A is the year, and column B is the dividend paid by the company for that year. If the value is not numeric (n.a.), then it means no dividend paid. But to make it simple, only count from the first cell with numeric value in the range (cell B5 in the example). To get the percentage of years that a company had positive dividend growth, I just specify it as: DivGrowth(B1:B20). Column C indicates if there is a dividend growth: 1 means dividend is better than last year, 0 otherwise. The expected result is shown in cell F5.

    I hope the function can be flexible. For example, if there are less than 5 numeric data points in the range specified, then just do not calculate and simply return a "-" or a blank space "". Also, ignore the first few cells which all have "n.a." values: just count from the first valid numeric data point (cell B5 in that example).
    Attached Files Attached Files

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Looking for a UDF to calculate for a practical question

    Hello alice2011,

    The attached workbook has the UDF shown below added to it. The UDF will ignore rnages with less than 5 cells and simply return a blank. The UDF scan the range to find the first numeric value in the range. Any non numeric values after that point are counted by summed as a zero value. Check this over a let me know if I missed anything.

    [b}UDF Macro Code[/b]
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    01-16-2014
    Location
    London
    MS-Off Ver
    Excel 2003 Excel 2010
    Posts
    189

    Re: Looking for a UDF to calculate for a practical question

    Hi, Leith Ross, your code works perfectly. Really nice

    A big thank you to you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Downsize long numbers (GB) to something more practical
    By Modify_inc in forum Excel General
    Replies: 5
    Last Post: 09-26-2011, 10:29 AM
  2. A Practical Problem
    By boranj in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-09-2011, 01:59 PM
  3. Most practical way to do the following (IF)condition.
    By Kenneth Yick in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-28-2011, 05:38 AM
  4. Is it practical? please comment
    By rookie37 in forum Excel General
    Replies: 2
    Last Post: 05-25-2010, 12:11 AM
  5. What Practical Applications Are There For Students?
    By DenniGa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-24-2009, 03:48 AM

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