السلام عليكم
جرب التعديل التالي
Sub Abu_Ahmed()
On Error Resume Next
Application.ScreenUpdating = False
Range("K7:N100").ClearContents
w = 7
For Each cl In [B2:B23]
If cl = [N3] And cl.Offset(0, 1) = [N4] Then
MyArr = MyArr & Trim(cl.Offset(0, -1)) & ","
End If
Next
If MyArr = Empty Then MsgBox "رقم القسم غير موجود لهذه المدرسة فرجاء تصحيح الخطأ ", vbOKOnly, "تنبيه": GoTo 1
For Each c In Split(Mid(MyArr, 1, Len(MyArr) - 1), ",")
Cells(w, 11) = c
Cells(w, 12) = [N3]
Cells(w, 13) = [N4]
Cells(w, 14) = Application.VLookup(c, [A2:D23], 4, 0)
w = w + 1
Next
LR = [K1000].End(xlUp).Row
Range(Cells(6, "K"), Cells(LR, "N")).Sort Key1:=Cells(6, "N"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
1:
Application.ScreenUpdating = True
End Sub