How in calc basic create SheetCellRanges

In calc basic,

thisSheet = ThisComponent.CurrentController.ActiveSheet
cellRange1 = thisSheet.getCellRangeByPosition( c1, r1,  c1, r2 )
cellRange2 = thisSheet.getCellRangeByPosition( c2, r3,  c2, r4 )

such that cellRange1 and cellRange2 do not intersect.

' cellRanges = cellRange1 + cellRange2		Err 380 Incorrect Property Value
' cellRanges = cellRange1 & cellRange2		Err 380 Incorrect Property Value
cellRanges = cellRange1 ~ cellRange2		'Err Unexpected Symbol: Attribute

So what’s the LO basic way of creating a union of Cell Ranges?

Thanks,
Mike

[Edit Opaque] Removed the <pre> tag for better readability.

What about cellRanges = ThisComponent.getSheets.getCellRangesByName( cellRange1.AbsoluteName & ";" & cellRange2.AbsoluteName)?

    Thank you, JohnSUN, your offering doesn't give me a range as in 
VBA but it does give me something I can use.
    It ends up being an object with the properties of an array that 
can be indexed into.
ThisComponent.CurrentController.Select(cellRanges) only selects 
the last cellRange added to cellRanges but they are accessable  as 
For i in 0 to UBound(cellRanges)
    doSomething(cellRanges(i))
Next

Much obliged,
Mike

To be honest, your request surprised me. Usually, when processing ranges, programmers tend to go from large to small, get separate cellRange from cellRanges, and in each of them reach a separate cell. You asked about the inverse task - having separate ranges to collect them in cellRanges. As you can see, this can be done, but to process the result, you will again have to process each part separately (analogue of the Area in the VBA)

Yes, I figured that out myself after exploring your solution. Coming from VBA where the opposite is true it caught me by surprise but I’ve already found a way to deal with each cell in such a construct.

By the way I found your runMacro routine posted in ask.libreoffice.org/en/question/242176 to be very useful.

Much appreciated,

Be well,
Mike

JohnSUN’s solution above is very usable but as Lupp pointed out here:

it doesn’t really give me SheetCellRanges object but rather a sequence of SheetCellRange
objects which takes a loop within a loop to access the cells.

The SheetCellRanges object is enumerable allowing easier access to the individual cells.

r1 = ThisComponent.CurrentController.ActiveSheet.getCellRangeByPosition(0,0,1,1)   
r2 = ThisComponent.CurrentController.ActiveSheet.getCellRangeByPosition(2,2,3,3)

oRanges = ThisComponent.createInstance("com.sun.star.sheet.SheetCellRanges")
oRanges.addRangeAddress(r1.RangeAddress,  False)
oRanges.addRangeAddress(r2.RangeAddress,  False)
oCells = oRanges.Cells.createEnumeration 
While oCells.hasMoreElements 
	doSomethingWith( oCells.nextElement )
Wend

Hope this helps the next guy.
Be well,
Mike

(Edit: fixed < code > section formatting -AK)