How do I restore a reference to a sheet after deleting a range of cells?

Is everything correct here as intended?

IMHO, the sheet should always be complete, without pieces. This is absurd.
I assume that after deleting a range of cells, it is replaced by other cells with the same addresses as those just deleted.

oSheet = ThisComponent.CurrentController.ActiveSheet
With oSheet
    ' NOTE: oAddress covers B522:O522.
    .removeRange(oAddress, com.sun.star.sheet.CellDeleteMode.UP)
End With

After removal, the sheet is broken into pieces. The above range (oAddress) is excluded from it. Why?
oSheet.AbsoluteName (see screenshot):
Снимок экрана от 2021-11-23 10-25-22

As a result, the sheet reference becomes broken too.
Calc hangs in stop mode. If you do not interrupt the execution of the program, then getting a cell that is not on the sheet leads to an out-of-range error. And I just need the cell that took the place of the deleted one (B522).
I have to set again the reference to the sheet.
oSheet = ThisComponent.CurrentController.ActiveSheet 'Okay
oSheet = .Spreadsheet 'leads to hang
Or is there another way? And is there a bug here?

See the oSheet reference state in break mode after deleting a range of cells (below). Pay attention to the Value column in the screenshot. It’s blank.

Снимок экрана от 2021-11-23 10-25-56


Version: 7.2.3.1 / LibreOffice Community Build ID: 7b257967b9cd574cb72598999edde852baa10d80 CPU threads: 8; OS: Linux 4.15; UI render: default; VCL: gtk3 Locale: ru-RU (ru_RU.UTF-8); UI: en-US Calc: threaded

UPDATED: I can understand that when deleting, the indexing in the loop (access by index) is violated, but so that the whole sheet disintegrates into parts… I don’t understand. This does not correspond to the real situation. We still have the entire sheet. The reference to the sheet should have been updated automatically. Or am I wrong?

I can confirm the behavior… with LO6.1.5.2 …

Intressingly with deletmode LEFT thereis no unwanted side-effect:

2021-11-23_633x183_scrot

@karolus, thanks. So this is a bug. Someone else would help to file the bug-report. There is absolutely no time.

I would not strictly say ‘bug’, to some degree its a expectable Implementationdetail, but yes, it should behave in both cases the same way!

There is someone here to clarify the question, but he asked me not to ping/mention him. And I promised. :slightly_smiling_face: