Get cell range from a cell that contains a formula array?

In my code I have a function that takes in a single cell. If the cell is part of a formula array eg: {=MyCustomFn(A2:C4)}.
And lets say the Formuala array covers Cells D1:E4. And now my function has get passed cell D4.

Is is possible when only D4 is available to my function to get the rest of the cells that are part of the formula array?

def my_fn(cell: Any) -> Any:
    formula = cell.getFormula()
    if formula.startswith("{="):
        is_formuala_array = True
    else:
        is_formuala_array = False
    # get the cell range for the formulay array
    # What goes here? How do I get the range of cells that the formula is for?

Still not using MRI? The cell has method getArrayFormula() which is empty if there is none.
and for the rest:

def getCurrentArray(oCell):
	oCursor = oCell.getSpreadSheet.createCursorByRange(oCell)
	oCursor.collapseToCurrentArray
	return oCursor
1 Like

@Villeroy your knowledge makes it all seem so easy.
Thank you.


Because python is case sensitive and need the () for function calls.

def getCurrentArray(cell):
    cursor = cell.getSpreadsheet().createCursorByRange(cell)
	cursor.collapseToCurrentArray()
	return cursor

I just look it up in Mri. ArrayFormula is one of the first pseudo-properties.

P.S. I forgot to mention, that there is a glitch with the ArrayFormula. When you set it, you have to specify the formula without the outer braces. When you get it, you get it with the braces.
OK, the cursor is not that easy to find. Have a look what it has to offer.

1 Like