Q:

Exl vba - range sort error

I have two range-sort parts in my code:
With ws1 

  finalrow1 = .Cells(.Rows.Count, "A").End(xlUp).Row

   With .Range(.Cells(6, 1), .Cells(finalrow1, 9))
    .Sort Key1:=.Cells(6, 8), Order1:=xlDescending, _
          Key2:=.Cells(6, 6), order2:=xlDescending, _
          Key3:=.Cells(6, 2), order3:=xlDescending, Header:=xlGuess
   End With

End With

With ws4

finalrow4 = .Cells(.Rows.Count, "A").End(xlUp).Row

   With .Range(.Cells(6, 1), .Cells(finalrow4, 8))
   .Sort Key1:=.Cells(6, 8), Order1:=xlDescending, _
         Key2:=.Cells(6, 6), order2:=xlDescending, _
         Key3:=.Cells(6, 4), order3:=xlDescending, _
         Key4:=.Cells(6, 2), order4:=xlDescending, Header:=xlGuess
   End With

End With

Where ws1 and ws4 are:
Set ws1 = ThisWorkbook.Sheets("Sheet1")
Set ws4 = ThisWorkbook.Sheets("Sheet4")

On the second "sort" I get Application-defined or object-defined error. This is just a part of the code.
I also have ws2 and ws3 that are in another excel file.
Is the problem in range selection or in sheet selection?

A:

The problem with the second sort is excel allows max three columns to sort simultaneously through VBA. 
If you sort multiple columns H, F, D and B manually, the excel sorts them in the reverse order internally to complete the sort i.e. it sorts the columns in the sequence B, D, F and H.
So you may use this concept to apply sort on more than three columns through VBA. All you need is to apply sort on the last column first separately and then apply sort on the remaining three columns as usual.
Please give this a try...
With ws4
    finalrow4 = .Cells(.Rows.Count, "A").End(xlUp).Row
    With .Range(.Cells(6, 1), .Cells(finalrow4, 8))
     .Sort Key1:=.Cells(6, 2), order1:=xlDescending, Header:=xlGuess
     .Sort Key1:=.Cells(6, 8), order1:=xlDescending, _
           Key2:=.Cells(6, 6), order2:=xlDescending, _
           Key3:=.Cells(6, 4), order3:=xlDescending, Header:=xlGuess
    End With
End With

