T
Tendresse
Hi all,
I have a worksheet that has 106 columns, some of them have dates, some have
text, etc. I want to write a macro to allow users to sort the list in
ascending order based on the column of their choice, by asking the user to
enter the letter of the alphabet located on top of the column. I’m using
excel 2003. I don’t seem to get the code right yet. I would appreciate it if
someone tells me where I went wrong:
Sub SORT()
‘ code that will select the range to be sorted
‘ Ask user which column they want to sort by
Dim ColumnToSort as String
ColumnToSort = InputBox (“Please enter the index of the column you wish to
sort byâ€)
If ColumnToSort = Ҡthen
Exit Sub
End If
‘Here is where I’m stuck. I don’t know how to use the ColumnToSort as the Key1
‘I want Key1 to be the cell in Row number 13 and Column ColumnToSort
Selection.Sort Key1:=Range(ColumnToSort & 13), Order1:=xlAscending,
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End sub
I have a worksheet that has 106 columns, some of them have dates, some have
text, etc. I want to write a macro to allow users to sort the list in
ascending order based on the column of their choice, by asking the user to
enter the letter of the alphabet located on top of the column. I’m using
excel 2003. I don’t seem to get the code right yet. I would appreciate it if
someone tells me where I went wrong:
Sub SORT()
‘ code that will select the range to be sorted
‘ Ask user which column they want to sort by
Dim ColumnToSort as String
ColumnToSort = InputBox (“Please enter the index of the column you wish to
sort byâ€)
If ColumnToSort = Ҡthen
Exit Sub
End If
‘Here is where I’m stuck. I don’t know how to use the ColumnToSort as the Key1
‘I want Key1 to be the cell in Row number 13 and Column ColumnToSort
Selection.Sort Key1:=Range(ColumnToSort & 13), Order1:=xlAscending,
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End sub