استبدل الدالة الكاملة السابقة ، بهذا التعديل :-
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
Dim lastRow As Long
Dim cell As Range
Dim pctCol As Range
Dim pct As Double
Dim grade As String
Dim i As Long
Set ws = Me
lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
If lastRow < 2 Then Exit Sub
Set pctCol = Intersect(Target, ws.Range("F2:F" & lastRow))
If Not pctCol Is Nothing Then
On Error GoTo CleanUp
Application.ScreenUpdating = False
Application.EnableEvents = False
For Each cell In pctCol
If IsNumeric(cell.Value) And cell.Value <> "" Then
pct = CDbl(cell.Value)
Select Case pct
Case Is >= 92.1: grade = "ممتاز مع المرتبة"
Case Is >= 90.1: grade = "ممتاز"
Case Is >= 85.1: grade = "جيد مع مرتبة الشرف"
Case Is >= 75.1: grade = "جيد جدا"
Case Is >= 65: grade = "جيد"
Case Is >= 50: grade = "مقبول"
Case Else: grade = "راسب"
End Select
ws.Cells(cell.Row, "E").Value = grade
End If
Next cell
With ws.Sort
.SortFields.Clear
.SortFields.Add Key:=ws.Range("F2:F" & lastRow), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
.SortFields.Add Key:=ws.Range("B2:B" & lastRow), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange ws.Range("A1:M" & lastRow)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.Apply
End With
For i = 2 To lastRow
If ws.Cells(i, "B").Value <> "" Then
ws.Cells(i, "A").Value = i - 1
End If
Next i
CleanUp:
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub
الملف بعد التعديل :-
لابلبلبلبلبلب.xlsm