当前位置: 动力学知识库 > 问答 > 编程问答 >

excel vba - macro to sort by selected column

问题描述:

I am very new to macros, so I need help with this. I want to sort the excel sheet by a selected column. For example if I have three columns "column1, column2 and column3", I want to be able to select one of the three columns to sort the entire sheet

网友答案:

Here is a simple example for a descending sort with a Header cell:

Sub SortsRUs()
    Set r = Application.InputBox("Click on a cell in the sort column", Type:=8).EntireColumn(1)
    ActiveSheet.UsedRange.Sort Key1:=r, Order1:=xlDescending, Header:=xlNo, _
            OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
            DataOption1:=xlSortNormal
End Sub
分享给朋友:
您可能感兴趣的文章:
随机阅读: