I have thousands of rows of 5 numbers in columns B-F that I need to sort horizontally in ascending order. I am trying to use VBA for this because I want each individual line to be in order.
For an example.
22 5 38 99 01 will need to be 01 05 22 38 99
and so on for the next row under neath it. I tried recording a code but it keeps the rows in my recording. I'd like it to go to the next row "X" and sort for columns B-F and then repeat about 2000 times.
Any suggestions on how to rewrite this?
Thanks in advance.
Sub Macro1()
'
' Macro1 Macro
'
'
ActiveWorkbook.Worksheets("history").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("history").Sort.SortFields.Add2 Key:=Range _
("B114:F114"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("history").Sort
.SetRange Range("B114:F114")
.Header = xlGuess
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
Range("B115:F115").Select
ActiveWorkbook.Worksheets("history").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("history").Sort.SortFields.Add2 Key:=Range _
("B115:F115"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("history").Sort
.SetRange Range("B115:F115")
.Header = xlGuess
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
Range("B116:F116").Select
ActiveWorkbook.Worksheets("history").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("history").Sort.SortFields.Add2 Key:=Range _
("B116:F116"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("history").Sort
.SetRange Range("B116:F116")
.Header = xlGuess
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
End Sub
Bookmarks