Thursday, 13 September 2012

Excel VBA Macro to Sort the Data

Excel VBA Macro to Sort the  Data Based on a Particular Column
Sub SORTDATA()
Dim X As Integer
On Error GoTo TPR

X = InputBox("Enter The SortBase Column:")
    Columns(X).Select
    
    ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
    ActiveWorkbook.ActiveSheet.Sort.SortFields.ADD Key:=Cells(1, X), _
        SortOn:=xlSortOnValues, _
        Order:=xlAscending, _
        DataOption:=xlSortNormal
        
    With ActiveWorkbook.ActiveSheet.Sort
        .SetRange Range("A1:z1000")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
TPR:
End Sub

No comments:

Post a Comment

Follow Me by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts