« Basic functions : SUBTOTAL | Main | Counting letters in a string »
March 03, 2005
Macro : Sorting sheets
A simple macro for sorting sheets in a spreadsheet in ascending alphabetical order.
Sub SortSheets
Dim oSheets
Dim oSheet
Dim i As Integer
Dim swap As Boolean
oSheets = ThisComponent.Sheets
If oSheets.getCount() > 1 Then 'No sorting for one sheet
Do
swap = False 'We continue bubble sort passes until no more swaps
For i = 0 to oSheets.getCount()-2
If oSheets.getByIndex(i).Name >
oSheets.getByIndex(i+1).Name Then
oSheets.moveByName(oSheets.getByIndex(i+1).Name,i)
swap = True
End If
Next
Loop Until swap = False
End If
End Sub
Posted by Dave at March 3, 2005 04:02 AM
Comments
some simple and elegant solution! thanks for helping us understand this wonderful Calc program
Posted by: celia palacios at March 26, 2005 07:36 AM