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).
Bookmarks