I know this subject has been beat to death. I can't seem to find the specific answer I am looking for though. I need to sort blocks of data as I move down a spreadsheet.
The following code works (generally). It only sorts on the first column though. For example, if the block is C5:L8, I need it to sort on C5 Primary and E5 secondary. I thought that is what my rKeyRange is doing. But, it is not working. When I sort manually, it is working (originally, the strings were unsortable). Setting the range with Cells() seems easier to deal with since it is so dynamic.
Bottom line: Question is how to set the rKeyRange to sort on 2 columns and set it dynamically as I move down the sheet.
The following code works (generally). It only sorts on the first column though. For example, if the block is C5:L8, I need it to sort on C5 Primary and E5 secondary. I thought that is what my rKeyRange is doing. But, it is not working. When I sort manually, it is working (originally, the strings were unsortable). Setting the range with Cells() seems easier to deal with since it is so dynamic.
Bottom line: Question is how to set the rKeyRange to sort on 2 columns and set it dynamically as I move down the sheet.
Code:
Private Sub RangeSort(iFirstRow As Long, iBlockSize As Long, iFirstCol As Long, iLastCol As Long) Dim rDataRange As Range
Dim rKeyRange As Range
Set rDataRange = Range(Cells(iFirstRow, iFirstCol), Cells(iFirstRow + iBlockSize, iLastCol))
rDataRange.Select
Set rKeyRange = Range(Cells(iFirstRow, 3), Cells(iFirstRow, 5))
rDataRange.Sort Key1:=rKeyRange, Order1:=xlAscending
End Sub