غريب الكود يشتغل معي بشكل جيد
اليك حل اخر لاختيار ما يناسبك
Option Explicit
Sub SortArray()
Dim a() As Variant, i As Long, j As Long, col As Long
Dim temp As Variant, lastRow As Long, OnRng As Range
Dim WS As Worksheet: Set WS = Sheets("Sheet1")
lastRow = WS.Cells(WS.Rows.Count, 1).End(xlUp).Row
Set OnRng = WS.Range("A1:E" & lastRow)
a = OnRng.Value
For i = 2 To UBound(a, 1) - 1
For j = i + 1 To UBound(a, 1)
If a(i, 3) < a(j, 3) Then
For col = 1 To UBound(a, 2)
temp = a(i, col)
a(i, col) = a(j, col)
a(j, col) = temp
Next col
ElseIf a(i, 3) = a(j, 3) Then
If a(i, 4) > a(j, 4) Then
For col = 1 To UBound(a, 2)
temp = a(i, col)
a(i, col) = a(j, col)
a(j, col) = temp
Next col
ElseIf a(i, 4) = a(j, 4) Then
If a(i, 5) > a(j, 5) Then
For col = 1 To UBound(a, 2)
temp = a(i, col)
a(i, col) = a(j, col)
a(j, col) = temp
Next col
End If
End If
End If
Next j
Next i
OnRng.Value = a
End Sub
ترتيب الاوائل v2.xlsb