B
Ben McClave
Hans,
I think I have a solution. First, add a line just above the CAPPED text inyour last post so that it looks like this:
Call SortIt(lStartRow, lRows, Sheet1)
lStartRow = lRows + 4
This will call a new Sub to sort the data in the range A:L using column B for the rows we copied. Here is the Sub to perform the sort:
Sub SortIt(lFirstRow As Long, lLastRow As Long, ws As Worksheet)
With ws.Sort
.SortFields.Clear
.SortFields.Add Key:=Range("B" & lFirstRow & ":B" & lLastRow) _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
.SetRange Range("A" & lFirstRow & ":L" & lLastRow)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
The idea behind this is that since we know that the data falls into the columns A:L, with B as the sort column, and we also know the first and last rows of data (lStartRow and lRows, respectively), we can build the ranges used by the macro you recorded and make it more dynamic.
Hope this helps,
Ben
I think I have a solution. First, add a line just above the CAPPED text inyour last post so that it looks like this:
Call SortIt(lStartRow, lRows, Sheet1)
lStartRow = lRows + 4
This will call a new Sub to sort the data in the range A:L using column B for the rows we copied. Here is the Sub to perform the sort:
Sub SortIt(lFirstRow As Long, lLastRow As Long, ws As Worksheet)
With ws.Sort
.SortFields.Clear
.SortFields.Add Key:=Range("B" & lFirstRow & ":B" & lLastRow) _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
.SetRange Range("A" & lFirstRow & ":L" & lLastRow)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
The idea behind this is that since we know that the data falls into the columns A:L, with B as the sort column, and we also know the first and last rows of data (lStartRow and lRows, respectively), we can build the ranges used by the macro you recorded and make it more dynamic.
Hope this helps,
Ben