OpenOffice Calc macro: sort a cell range

sortRange(destSheet, 0, y1, 25, J-1)

…

Sub sortRange(oSheet as Object, x1 as Integer, y1 as Integer, x2 as Integer, y2 as Integer)
 Dim aSortFields2(2) as Object 
 Dim aSortDesc(0) as New com.sun.star.beans.PropertyValue 
 For i =0 to 2 
 aSortFields2(i)= New com.sun.star.util.SortField 
 Next i

oRange = oSheet.getCellRangeByPosition(x1, y1, x2, y2) 'range B1:F7

aSortFields2(0).Field = 6 
 aSortFields2(0).SortAscending = True 'sort ascending by column G
 aSortFields2(1).Field = 11 
 aSortFields2(1).SortAscending = True 'then sort ascending by column L
 aSortFields2(2).Field = 12 
 aSortFields2(2).SortAscending = True 'then sort ascending by column M
 aSortDesc(0).Name = "SortFields" 
 aSortDesc(0).Value = aSortFields2() 
 oRange.Sort(aSortDesc()) 
End Sub

Reference:

How to sort a cellrange in Calc using Basic




Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>