Hi,

I am very new to VBA and macro programming, but need urgently to calculate moving averages for a data series in a rather complicated manner. I hope someone can kindly offer advice to the problem below.

Suppose I have a hundred data points in cells A1 to A100, and two numbers in cell B1 and C1. Further suppose that these data are only determined at runtime.

I need to calculate moving averages based on the data points in A1 to A100, where the number in B1 determines the number of data points that goes into the calculation of each moving average figure, and the number in B2 determines the "gap" between the data points. Let me illustrate with an example.

Suppose B1 = 6 and B2 = 2, and I am calculating the moving averages to fill in the blanks D1 to D10.

Therefore D1 = the average of (A1 + A4 + A7 + A10 + A13 + A17), and D2 = the average of (A2 + A5 + A8 + A11 + A14 + A18) etc.

In this case, B1 = 6 determines the number of data points that is used to calculate each moving average (for the example 6 values from series A is used to calculate each value in series D). B2 =2 determines the "gap" between each data point i.e. the average for D1 is taken for A1, A4 (skipping 2 numbers A2 and A3), A7 (skipping 2 numbers A5 and A6) and so on.

If B1 = 4 and B2 = 1, then D1 = the average of (A1 + A3 + A5 + A7) and D2 = the average of (A2 + A4 + A6 + A8).

How can I go about doing this? Any VBA code examples will be most appreciated!