|
- Sub 按钮12_Click()
- arr = Sheets("学生名单").[a1].CurrentRegion
- Set d = CreateObject("scripting.dictionary")
- Set dd = CreateObject("scripting.dictionary")
- For j = 2 To UBound(arr)
- x = Format(arr(j, 6), "00") & "栋"
- If Not d.exists(x) Then
- Set d(x) = CreateObject("scripting.dictionary")
- End If
- If Not d(x).exists(arr(j, 7) & "") Then
- Set d(x)(arr(j, 7) & "") = CreateObject("scripting.dictionary")
- End If
- d(x)(arr(j, 7) & "")(j) = j
- Next j
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- For Each sh In Sheets
- If d.exists(sh.Name & "") Then
- For Each cmt In sh.Comments
- cmt.Delete
- Next cmt
- r = sh.Cells(Rows.Count, 1).End(3).Row
- For j = 3 To r Step 4
- For i = sh.Cells(j, Columns.Count).End(xlToLeft).Column To 2 Step -1
- If d(sh.Name & "").exists(sh.Cells(j, i) & "") Then
- dd.RemoveAll
- y1 = sh.Name & ""
- y2 = sh.Cells(j, i) & ""
- y3 = d(sh.Name & "")(sh.Cells(j, i) & "").Count
- sh.Cells(j + 1, i) = d(sh.Name & "")(sh.Cells(j, i) & "").Count
- For Each k In d(sh.Name & "")(sh.Cells(j, i) & "").keys
- dd(arr(k, 2)) = dd(arr(k, 2)) & Chr(10) & arr(k, 3) & "-" & arr(k, 8)
- Next k
- If dd.Count = 1 Then
- sh.Cells(j + 2, i) = dd.keys()(0)
- Else
- sh.Cells(j + 2, i) = Join(dd.keys, ",")
- sh.Cells(j + 2, i).Interior.ColorIndex = 6
- End If
- If sh.Cells(j + 2, i) = sh.Cells(j + 2, i + 1) Then
- sh.Cells(j + 2, i).Resize(1, 2).Merge
- End If
-
- str1 = ""
- For Each k In dd.keys
- str1 = str1 & Chr(10) & k & Chr(10) & dd(k)
- Next k
- sh.Cells(j, i).AddComment
- sh.Cells(j, i).Comment.Visible = False
- sh.Cells(j, i).Comment.Text Text:=str1
- sh.Cells(j, i).Comment.Shape.Height = 200
- End If
- Next i
- Next j
- End If
- Next sh
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|