Dear Friends,
Please find the code for sorting data:
I have around 50,000 rows of data and need to sort this data in 3 levels.
This takes a lot of time.
Please tell me how this can be achieved in a shorter duration.
Thanks
megha
Please find the code for sorting data:
Code:
Sub SortData()
Dim nLastRow, Rownum As Integer
nLastRow = 0
Rownum = 0
Worksheets("Sheet2").Activate
Sheets("Sheet2").Select
nLastRow = Range("A" & Rows.Count).End(xlUp).Row
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.clear
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range("B:B") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range("D:D") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range("E:E") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet2").Sort
.SetRange Rows("1:" & nLastRow)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
I have around 50,000 rows of data and need to sort this data in 3 levels.
This takes a lot of time.
Please tell me how this can be achieved in a shorter duration.
Thanks
megha