I'm trying to write a macro that would sort rows in ascending order within a selection. With one line it works, but with several lines it starts to work in a strange way. Tell me please, am I missing something?
Code: Select all
Sub TableSort1
Dim oSortFields(0) as new com.sun.star.util.SortField
Dim oSortDesc(1) as new com.sun.star.beans.PropertyValue
document = ThisComponent
osheet = ThisComponent.CurrentController.ActiveSheet
oSelection = ThisComponent.getCurrentSelection()
Rows = oSelection.getRows().getCount()
For i = 0 to Rows Step 1
oSortFields(0).Field = i
oSortFields(0).SortAscending = TRUE
oSortDesc(0).Name = "SortFields"
oSortDesc(0).Value = oSortFields()
oSortDesc(1).Name = "IsSortColumns"
oSortDesc(1).Value = FALSE
oSelection.Sort(oSortDesc())
Next
End Sub