Hello,
I have a simple question that i can’t seem to find the answer to. How can I get the column index number from it’s header name, not from A or AA, but from “Category” and such.
My code down here, I simply want to sort by column names instead of hard coding their index.
Sub Srot_l
Dim oSheet1
oSheet1=ThisComponent.CurrentController.getActiveSheet.GetName
if oSheet1 = “List” then’ [‘A’, ‘B’], sort : Name, Type
oSheet = ThisComponent.Sheets.getByName(oSheet1)
oCellrange = oSheet.getCellrangeByName("B1:BA7000")
SortDesc = oCellrange.createSortDescriptor
SortDesc(1).Value = TRUE 'ContainsHeader
Dim l1(0) as New com.sun.star.table.TableSortField
l1(0).Field = 2
l1(0).IsAscending = "True"
SortDesc(3).Value = l1() 'SortFields
oCellrange.sort(SortDesc)
Dim l2(0) as New com.sun.star.table.TableSortField
l2(0).Field = 1
l2(0).IsAscending = "True"
SortDesc(3).Value = l2() 'SortFields
oCellrange.sort(SortDesc)
end if
End Sub