I am trying to write a vba function that takes a range as an argument and returns some coefficients to the worksheet. But when I try to write anything to my worksheet from the function, I get an undefined value (#VALUE!). When I change function to macro(sub) and hardcode the arguments in the function, it allows me to set values in worksheet.
' these don't work
Sheets("Sheet1").Cells(4, 1) = x
Sheets("Sheet1").Range(4, 1) = x
Can you please give me a simple example of a function that takes a range of values as arguments, calculates something, and writes answers back to worksheet.