Q:

Object required while sorting a range

I'm trying to sort a range by a column:
Private Sub sort_all_by_group()
    Dim last_row As Integer
    Dim selected_cells
    Dim sort_criterion
    last_row = find_last_row()

    With Worksheets(MAIN_SHEET)
        selected_cells = Range(.Cells(2, 1), .Cells(last_row, LAST_COL))
        sort_criterion = Range(.Cells(2, 2), .Cells(last_row, LAST_COL))

        ' Run-time error 424: Object required.
        selected_cells.Sort key1:=sort_criterion, order1:=xlAscending, Header:=xlNo 

    End With

End Sub

In the comment I specified what the error is.
Selected_cells is a range object.

A:

If selected_cells is a range you have to use the set keyword. It would also be good to decleare it properly then
Private Sub sort_all_by_group()
    Dim last_row As Integer
    Dim selected_cells As Range
    Dim sort_criterion As Range
    last_row = find_last_row()

    With Worksheets(MAIN_SHEET)
        Set selected_cells = .Range(.Cells(2, 1), .Cells(last_row, LAST_COL))
        Set sort_criterion = .Range(.Cells(2, 2), .Cells(last_row, LAST_COL))
        selected_cells.Sort key1:=sort_criterion, order1:=xlAscending, Header:=xlNo 
    End With

End Sub

