I'm trying to sort a range based on a specific criteria when the user select check boxes from a user form in Excel.
The user is given the option of 4 check boxes (each check box will sort a specific range). I've tried a few methods and can't seem to figure it out, I keep getting "Object Required" on run-time error
Private Sub btnConfirm_Click()
If (chkbxValid.value) Then
SortData (Range("H4:I1000"))
End If
If (chkbxValidDuplicate.value) Then
SortData (Range("K4:L1000"))
End If
If (chkbxInvalid.value) Then
SortData (Range("N4:O1000"))
End If
If (chkbxInvalidDuplicate.value) Then
SortData (Range("Q4:R1000"))
End If
End Sub
And then here's the second segment of code
Private Function SortData(rng As Range)
FR = 1
FC = 1
LR = 1000
LC = 2
SC = 2
Sheets("TRACKER_2.0").rng(cells(FR, FC), cells(LR, LC)).Sort Key1:=Range(cells(FR, SC), cells(LR, SC)), Order1:=xlAscending
End Function
Key1
must specify the first sort field, you are using the whole range so that may have unintended consequences. – SJR