原始成绩一键导出平均分、优秀率、良好率、及格率和低分率的宏代码
时间: 2023-09-02 21:06:31 浏览: 161
成绩导出程序
以下是一个示例的VBA宏代码,用于一键导出原始成绩的平均分、优秀率、良好率、及格率和低分率:
```vba
Sub ExportStatistics()
Dim dataRange As Range
Dim average As Double
Dim excellentCount As Integer
Dim goodCount As Integer
Dim passCount As Integer
Dim lowCount As Integer
Dim totalCount As Integer
' 设置数据范围,将A2:A11替换为你的原始成绩数据范围
Set dataRange = Range("A2:A11")
' 计算平均分
average = WorksheetFunction.Average(dataRange)
' 计算各等级人数
For Each cell In dataRange
If cell.Value >= 90 Then
excellentCount = excellentCount + 1
ElseIf cell.Value >= 80 Then
goodCount = goodCount + 1
ElseIf cell.Value >= 60 Then
passCount = passCount + 1
Else
lowCount = lowCount + 1
End If
totalCount = totalCount + 1
Next cell
' 计算各等级比例
Dim excellentRate As Double
Dim goodRate As Double
Dim passRate As Double
Dim lowRate As Double
excellentRate = excellentCount / totalCount * 100
goodRate = goodCount / totalCount * 100
passRate = passCount / totalCount * 100
lowRate = lowCount / totalCount * 100
' 在B1:E5单元格中输出结果,可以根据需要进行调整
Range("B1").Value = "平均分"
Range("B2").Value = average
Range("C1").Value = "优秀率"
Range("C2").Value = excellentRate
Range("D1").Value = "良好率"
Range("D2").Value = goodRate
Range("E1").Value = "及格率"
Range("E2").Value = passRate
Range("F1").Value = "低分率"
Range("F2").Value = lowRate
End Sub
```
在这个示例中,你需要将`A2:A11`替换为你的原始成绩数据范围。代码会计算该范围内的平均分,并统计各个等级(优秀、良好、及格、低分)的人数和比例,然后将结果输出到B1:E5单元格中(你可以根据需要进行调整)。
将上述代码复制粘贴到Excel的VBA编辑器中(按下`Alt + F11`打开VBA编辑器),然后执行宏即可导出原始成绩的统计结果。
阅读全文