|
这个是chatgpt生成的代码帮我看看哪里逻辑错误,谢谢各路大侠!
Sub Admissions()
Dim sheet1 As Worksheet
Dim sheet2 As Worksheet
Dim sheet3 As Worksheet
Dim dict As Object
Dim lastRow1 As Long
Dim lastRow2 As Long
Dim lastRow3 As Long
Dim i As Long
Dim j As Long
Dim k As Long
Dim school As String
Dim minCount As Long
Dim score As Long
Dim admissionScore As Long
Dim admissionSchool As String
Dim quotaSchools As Dictionary
Dim quotaMinCounts As Dictionary
Dim quotaCounts As Dictionary
Dim graduateSchools As Dictionary
Set sheet1 = Worksheets("Sheet1")
Set sheet2 = Worksheets("Sheet2")
Set sheet3 = Worksheets("Sheet3")
Set dict = CreateObject("Scripting.Dictionary")
Set quotaSchools = New Dictionary
Set quotaMinCounts = New Dictionary
Set quotaCounts = New Dictionary
Set graduateSchools = New Dictionary
' 获取sheet2表中的学校志愿和最低录取分数线
lastRow2 = sheet2.Cells(Rows.Count, "E").End(xlUp).Row
For i = 2 To lastRow2
school = sheet2.Cells(i, "E").Value
minCount = sheet2.Cells(i, "K").Value
dict(school) = minCount
Next i
' 获取sheet3表中的指标录取志愿学校和最低录取人数
lastRow3 = sheet3.Cells(Rows.Count, "B").End(xlUp).Row
For i = 2 To lastRow3
school = sheet3.Cells(i, "B").Value
For j = 1 To 3
quotaSchools(school & j) = sheet3.Cells(i, j + 1).Value
quotaMinCounts(school & j) = sheet3.Cells(i, j + 1).Offset(1, 0).Value
quotaCounts(school & j) = 0
Next j
Next i
' 遍历sheet1表中的考生数据
lastRow1 = sheet1.Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To lastRow1
score = sheet1.Cells(i, "H").Value
admissionScore = -1
admissionSchool = ""
' 获取毕业学校
graduateSchool = sheet1.Cells(i, "J").Value
graduateSchools(sheet1.Cells(i, "A").Value) = graduateSchool
' 检查第一志愿是否是指标录取志愿学校
For j = 1 To 3
school = quotaSchools(graduateSchool & j)
If school = sheet1.Cells(i, "B").Value Or school = sheet1.Cells(i, "C").Value Then
' 检查该志愿学校是否还有指标名额
If quotaCounts(school & j) < quotaMinCounts(school & j) Then
admissionScore = dict(school)
admissionSchool = school
quotaCounts(school & j) = quotaCounts(school & j) + 1
Exit For
End If
End If
Next j
sheet1.Cells(i, "I").Value = IIf(admissionScore = -1, "未录取", admissionSchool)
Next i
' 在sheet2表中显示录取人数
For i = 1 To 3
sheet2.Cells(i + 1, "L").Value = quotaCounts(quotaSchools(graduateSchool & 1) & i)
Next i
End Sub |
|