Refer the cell containing the user defined function in that function

Viewed 30

I have a user defined function which manipulates the cells in the same row and column. Can the function detect in which cell the function is inserted? I can as well pass Google Sheets formulas ROW() and COLUMN() as arguments to the user defined function. Is there a better method?

1 Answers

I understand that your function writes some values into a cell. In that case, that cell would be known as the active cell. You can use the Selection class to get that cell as a Range object. Then, you can use the Range class methods as usual to work with that cell.

I will assume that your function writes the value using the Range.setValue() method. If that is correct, then you can get the cell even easier because that method returns the Range object for chaining. If these approaches don't work in your scenario, please share your code so I can help you better.

Related