@Lupp, thank you. I have noted the error information.
There are two similar solutions (second solution came from @sokol92 from another forum).
I'm testing and adapting them to fit my needs now.
Both solutions (above and here) are based on the autofill method to avoid iterating over cells.
Code: Select all
' Assigns a formula to cells in a rectangular range
Sub RangePutFormula(oRange, formula)
oRange.getCellByPosition(0, 0).Formula = formula 'the same leadCell
oRange.fillAuto(0, 1)
oRange.fillAuto(1, 1)
End Sub
' Assigns a formula to cells in multiple rectangular ranges
Sub RangesPutFormula(oRanges, formula)
Dim oRange
For Each oRange In oRanges
RangePutFormula oRange, formula
Next oRange
End Sub
' Checking for selected cells
Sub TestPutFormula()
Dim oRanges, formula
formula= "=A1"
oRanges = ThisComponent.CurrentSelection
If hasUnoInterfaces(oRanges, "com.sun.star.sheet.XSheetCellRanges") Then
RangesPutFormula oRanges, formula
Else
RangePutFormula oRanges, formula
End If
End Sub
But Google didn’t help me find this information...