Sub TeeTeht4()
Dim ws As Worksheet
Dim i As Long
Set ws = ActiveSheet
' Сортировка учеников по имени
ws.Range("A9:G22").Sort _
Key1:=ws.Range("A10"), _
Order1:=xlAscending, _
Header:=xlYes
' Заголовок "arvosanat" по центру относительно B:D
With ws.Range("B7:D7")
.HorizontalAlignment = xlCenterAcrossSelection
End With
' Средkiarvo, huonoin ja paras
For i = 10 To 22
ws.Cells(i, 5).Formula = "=AVERAGE(B" & i & ":D" & i & ")"
ws.Cells(i, 6).Formula = "=MIN(B" & i & ":D" & i & ")"
ws.Cells(i, 7).Formula = "=MAX(B" & i & ":D" & i & ")"
Next i
' Keskiarvo yhdellä desimaalilla
ws.Range("E10:E22").NumberFormat = "0.0"
' Sarakkeiden B-D leveys
ws.Columns("B:D").AutoFit
MsgBox "Valmis!"
End Sub