|
楼主 |
发表于 2023-7-6 15:43
|
显示全部楼层
本帖最后由 xiangme 于 2023-7-7 07:37 编辑
另外补充下:去尾的部分是对每个班级、每个学科的后20%都要去尾。
Sub ProcessData()
' 选择班级列
Dim classColumn As Integer
classColumn = Application.InputBox("请选择班级列", "选择班级列", Type:=1)
' 选择学科列
Dim subjectColumns As String
subjectColumns = Application.InputBox("请选择学科列(用逗号分隔)", "选择学科列", Type:=2)
Dim subjectColumnArray() As String
subjectColumnArray = Split(subjectColumns, ",")
' 对每个班进行筛选计数
Dim lastRow As Long
lastRow = Cells(Rows.Count, classColumn).End(xlUp).Row
Dim classCount As Object
Set classCount = CreateObject("Scripting.Dictionary")
For i = 2 To lastRow
Dim className As String
className = Cells(i, classColumn).Value
If Not classCount.Exists(className) Then
classCount.Add className, 1
Else
classCount.Item(className) = classCount.Item(className) + 1
End If
Next i
' 计算去尾人数并显示人数列表
Dim tailCount As Object
Set tailCount = CreateObject("Scripting.Dictionary")
For Each key In classCount.Keys
tailCount.Add key, Round(classCount.Item(key) * 0.2)
Next key
' 显示人数列表
Dim lastColumn As Long
lastColumn = Cells(1, Columns.Count).End(xlToLeft).Column
Dim resultRow As Integer
resultRow = 1
For Each key In tailCount.Keys
Cells(resultRow, lastColumn + 1).Value = key
Cells(resultRow, lastColumn + 2).Value = tailCount.Item(key)
resultRow = resultRow + 1
Next key
End Sub
上面的代码只能实现前三步,后面对去尾涂色、算所有班的平均分,搞不定,请大神出手。
|
|