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.
this function can be used like many of the inbuilt functions that are used within individual cells
but it will error if you try to affect other cells
This next method will need to be run as a macro either from a button or from running the macro manually. This method assumes that it will be passed two single cell ranges.