I'm getting a #Value! error with this. The udf I am creating should return the log average of the 8 cells to the left of the cell in which you type the function. I think the error has to do with how I'm selecting the range over which to loop. Would this work in a udf?
Set rngValues = Range.FormulaR1C1 = "(RC[-8]:RC[-1])"
I've used R1C1 to call the cells I am operating over but am unsure whether this is the best way to do it. Any helpful suggestions are welcome.
a) You use a UDF (User Defined Function) like any function that is part of Excel: If you want to calculate the sum of some cells, you write the formula
=Sum(A1:A10). You can do exactly the same for an own function: Just write=dbax(A1:A10)(adapt to the Range that you really want to use). Excel will pass the Range A1:A10 to the function.As written in the comments: Remove the
Set rngValues = ...line.rngValuesis set already, plus the syntax of the statement is invalid.b) Assuming that your data is okay (all cells contain numeric values), the function should work. However, you are not returning the calculated result: When your function name is
dbax, the last statement should be