Friday 25 September 2015

EXCEL Macro(VBA) Code to Sort the Data

EXCEL Macro(VBA) Code to Sort the Data Based on One Particular Column

First Enter the large data in Excel sheet then Execute this Macro

Sub Sorting()
Dim X As Integer

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:H300")
  .Header = xlYes
  .MatchCase = False
  .Orientation = xlTopToBottom
  .SortMethod = xlPinYin
  .Apply
 End With
End Sub

No comments:

Post a Comment