I'm trying to average some data sets which are in their own columns. The number of data sets may change, so the number of columns I average needs to be dynamic.
Also, I have multiple sets of data sets on each sheet, and because the data sets are dynamic, I add columns to the sheet earlier in the code, so I can't hardcode the starting point for the data set. In other words, I can't just say...
Range("L5").formula = "=AVERAGE(H5:K5)"
... because I can't know for sure that the data sets start at H5. It might start at F5, or G5, etc.
So I'm trying pass the a starting point as an argument in an As Range variable, but I don't know how interface this with a .formula.
The following code doesn't work. I'm guessing because I can't put a range variable in a string like this.
Sub Average()
Dim c As Range
Set c = Range("B5:B10")
Range("F5").FormulaR1C1 = "=Average(" & c & ")"
Is there any way to use ranges with excel formulas like this?