I know there are alternatives to this. You can simply pass the variables you want to pass to the custom function. But that's not what I want to happen. Something like:
=CUSTOMFUNCTION(A2,A3)(A4,A5)
Dynamically generating functions from a set of parameters. I can see this being useful in some places, but it definitely is niche.
I've tried passing the following:
return LAMBDA(var1, var1 + 1) // returns a "Undefined function" Error.
return "LAMBDA(var1, var1 + 1)" // returns a string. I tried appending a (A4) in Google Sheets, doesn't work.
return (var1) => var1 + 1 // returns a string, surprisingly.
I'm at least 90% certain that what I'm thinking of here is currently unsupported. But it would still be great if I can get an answer.
Range.setFormula()in that context. Make sure you are not asking an XY question.LAMBDAfunction is invalid on two counts. First, the variable ("var1") ends in a digit and (based on my limited testing) this seems to be a no-no - "var" is OK, "var1q" is OK, but "var1" will result in an error. Second, you need to include the cell reference containing the value of the variable. So, a valid function might be=lambda(var,var+1)(A2), where cell A2 contains the value of "var".setFormula(formula)Ref?setFormula()on a different cell. Also, good point @Tedinoz about the variable names, should have just stuck with foo and bar.