|
本帖最后由 yynrzwh 于 2024-8-3 10:14 编辑
楼上思路的程序实现
假设同班没有同名教师
Sub 分组()
Dim d As Object, lr&, r&, i&, j&, s$, ar
Dim flag As Boolean
Set d = VBA.CreateObject("scripting.dictionary")
With Sheet1
lr = .Cells(Rows.Count, 1).End(3).Row + 1
.Range("a2:a" & lr) = ""
ar = .Range("a1").CurrentRegion
End With
r = 1
Do
flag = False
For i = 2 To UBound(ar)
If Len(ar(i, 1)) = 0 Then
flag = True
If Not d.exists(i) Then
Set d(i) = VBA.CreateObject("scripting.dictionary")
End If
ar(i, 1) = r
For j = 3 To UBound(ar, 2)
s = Trim(ar(i, j))
If Len(s) > 0 Then
If isrep(s, d) Then
ar(i, 1) = ""
d.Remove i
Exit For
Else
d(i)(s) = ""
End If
End If
Next
End If
Next
r = r + 1
d.RemoveAll
Loop While flag
Sheet1.Range("a1").CurrentRegion = ar
Set d = Nothing
End Sub
Private Function isrep(teacher, d)
Dim flag As Boolean, k
flag = False
For Each k In d.keys
If d(k).exists(teacher) Then
flag = True
Exit For
End If
Next
isrep = flag
End Function
Sheet1.zip
(30.54 KB, 下载次数: 12)
|
评分
-
1
查看全部评分
-
|