Hello everybody,
Here is my original code, which goes down column F, from F4 on-wards. It averages 5 cells at a time, the result of which it places in column G, from G4 on-wards.
It uses relative values, so cell G14 will have the value of F14:18/5 and so on.
I have tested this with a fixed amount of data up to cell F255, meaning the formula can only calculate up to G250 as it needs the 5 cells below it in the F column to calculate a corresponding G value- and it has worked fine.
I would now like to apply the above formula to variable amounts of data, meaning that the F column's data will vary in length.
The G column needs to calculate for how ever much data there is in the F column minus 5 cells.
So if the F column populates from F4:F1000, I would need the G column to produce calculations in the range G4:G995.
So how can I make this formula work for variable amounts of data?
My thoughts so far have been to use an "xldown" function to select how many cells have data in column F (which will always hold contiguous data), thus stopping when there is an empty cell below. Then to deduct 5 from that value, and use "cell.offset" to place the end of the G range in the formula. Am I thinking about this correctly or is this fundamentally incorrect?
Any help is greatly appreciated and I would like to thank you for your time in reading my question.
Pete.
Here is my original code, which goes down column F, from F4 on-wards. It averages 5 cells at a time, the result of which it places in column G, from G4 on-wards.
It uses relative values, so cell G14 will have the value of F14:18/5 and so on.
Code:
Range("g4", "g250").Formula = "=SUM(F4:F8)/5"
I have tested this with a fixed amount of data up to cell F255, meaning the formula can only calculate up to G250 as it needs the 5 cells below it in the F column to calculate a corresponding G value- and it has worked fine.
I would now like to apply the above formula to variable amounts of data, meaning that the F column's data will vary in length.
The G column needs to calculate for how ever much data there is in the F column minus 5 cells.
So if the F column populates from F4:F1000, I would need the G column to produce calculations in the range G4:G995.
So how can I make this formula work for variable amounts of data?
My thoughts so far have been to use an "xldown" function to select how many cells have data in column F (which will always hold contiguous data), thus stopping when there is an empty cell below. Then to deduct 5 from that value, and use "cell.offset" to place the end of the G range in the formula. Am I thinking about this correctly or is this fundamentally incorrect?
Any help is greatly appreciated and I would like to thank you for your time in reading my question.
Pete.