Harry Covair
Member
Hello the forum,
I need help to solve a problem of syntax in the SORT function in VBA.
I want to sort the contents of a spreadsheet based on a criterion selected from a dropdown list. The sequence of items in the list corresponds to the sequence of column headings.
So I set the column to sort by the statement:
With
A message "Method 'Range' of object '_Global' failed" appears.
By cons, if I write
No error appears.
Could a member of the forum advice me on how to write the variable ColToSort.
Thanks in advance
Harry
I need help to solve a problem of syntax in the SORT function in VBA.
I want to sort the contents of a spreadsheet based on a criterion selected from a dropdown list. The sequence of items in the list corresponds to the sequence of column headings.
So I set the column to sort by the statement:
Code:
ColToSort = wksh.Range(Cells (5, dd.ListIndex)
- wksh = ActiveSheet
- dd.ListIndex the rank of the selection in the drop down list = column heading.
- 5 = the row containing the column headings.
Code:
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:= Range (ColToSort) _
SortOn: = xlSortOnValues, Order: = xlAscending, DataOption: = xlSortNormal
By cons, if I write
Code:
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key: = Range ("C5"), _
SortOn: = xlSortOnValues, Order: = xlAscending, DataOption: = xlSortNormal
Could a member of the forum advice me on how to write the variable ColToSort.
Thanks in advance
Harry