Google-sheets – Entire sheet as a function

google sheets

Is it possible to use an entire worksheet as a function? I would like to be able to define the inputs to the worksheet and then select a certain cell as the output and copy that multiple times.

I have a sheet that defines a cost model for Azure websites in a 30 day window. I'd like to be able to create another sheet that has a 12 month breakdown using the 30 day model I've defined. Is this possible?

Something like =MyCustomFunction([inputs into the model sheet]) which returns a single cell value which would be the cost.

Best Answer

Yes, it's possible. From Custom Functions in Google Sheets>Guidelines for custom functions>Arguments

If you call your function with a reference to a range of cells as an argument (like =DOUBLE(A1:B10)), the argument will be a two-dimensional array of the cells' values. For example, in the screenshot below, the arguments in =DOUBLE(A1:B2) are interpreted by Apps Script as double([[1,3],[2,4]]). Note that the sample code for DOUBLE from above would need to be modified to accept an array as input.

enter image description here