OaklandJim
Well-known Member
- Joined
- Nov 29, 2018
- Messages
- 906
- Office Version
- 365
- Platform
- Windows
Mr. Excelers
I am doing three very basic sorts on a tabular range of data ("database"). Two work as expected and results end up at the top of the data range. BUT I have a third sort for which the results are left at the bottom of the data range. I suspect that the third sort -- involving a column with formulas, not straight text -- needs something added to the sub that does the actual sorting.
There must be a way to sort on a column with formulas so that empty cells are placed below the cells with content.
Here is the sorting sub that I am using to do the actual sort. The sub that produces the bad result when it calls the sorting sub is below that.
I am doing three very basic sorts on a tabular range of data ("database"). Two work as expected and results end up at the top of the data range. BUT I have a third sort for which the results are left at the bottom of the data range. I suspect that the third sort -- involving a column with formulas, not straight text -- needs something added to the sub that does the actual sorting.
There must be a way to sort on a column with formulas so that empty cells are placed below the cells with content.
Here is the sorting sub that I am using to do the actual sort. The sub that produces the bad result when it calls the sorting sub is below that.
VBA Code:
Private Sub DoSort( _
prSortRangeWithHeaders As Range, _
piKey1Col As Long, _
Optional piKey2Col As Long = 1, _
Optional pbAscending As Boolean = True)
' ----------------------
' Error Handling
' ----------------------
Dim sSubName As String
Dim sStepID As String
sStepID = "Initializations"
sSubName = "DoSort"
On Error GoTo ErrHandler
' ----------------------
Dim vEnableStatus As Variant
With Application
vEnableStatus = .EnableEvents
.ScreenUpdating = False
.EnableEvents = False
End With
Dim vAscending As Variant
If pbAscending _
Then
vAscending = xlAscending
Else
vAscending = xlDescending
End If
sStepID = "Sorting"
prSortRangeWithHeaders.Sort _
Key1:=prSortRangeWithHeaders.Cells(2, piKey1Col), _
Key2:=prSortRangeWithHeaders.Cells(2, piKey2Col), _
Order1:=vAscending, _
Header:=xlYes
Application.EnableEvents = vEnableStatus
Exit Sub
ErrHandler:
Application.EnableEvents = True
Call ErrorMessage(Err.Number, Err.Description, sSubName, sStepID)
End Sub
VBA Code:
'Sort on plan types then providers
Sub SortMedPlans_PlanType()
Dim rSortRange As Range
Set rSortRange = [MedicalPlans].Range("MedicalPlansData")
Call DoSort(rSortRange, 5, 1)
End Sub