Okay, using this code, I have managed to sort things using a brute force technique (I create a column and copy the cell I am using to search into the 4 rows of that column, sort using that column, then delete the column, leaving the data).
However, I need a way to select ALL the data for the SortFields code (I recorded a macro for this code), not just the range it selects. I tested it with 12 sets of data and it gave me the range A1:H395, but I need it to work for any number of sets of data. Is there a way to reference ALL values in Columns A through H?
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
LastRow = Range("B65536").End(xlUp).Row
For r = LastRow To 1 Step -1
With Range("B" & r)
If .Value = "PositionN" Then
Range("F" & r).Select
Selection.Copy
Range("A" & r + 1, "A" & r - 2).Select
ActiveSheet.Paste
End If
End With
Next r
Columns("A:A").Select
ActiveWorkbook.Worksheets("Input").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Input").Sort.SortFields.Add Key:=Range("A1"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Input").Sort
.SetRange Range("A1:H395")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Bookmarks