|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("上学期名单")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a3:f" & r)
- For i = 1 To UBound(arr)
- d(arr(i, 1)) = i
- Next
- End With
- With Worksheets("下学期名单")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- brr = .Range("a3:f" & r)
- ReDim drr(1 To UBound(brr), 1 To UBound(brr, 2))
- m = 0
- For i = 1 To UBound(brr)
- If Not d.exists(brr(i, 1)) Then
- m = m + 1
- For j = 1 To UBound(brr, 2)
- drr(m, j) = brr(i, j)
- Next
- Else
- d.Remove (brr(i, 1))
- End If
- Next
- End With
- tt = d.items
- If d.Count > 0 Then
- ReDim crr(1 To d.Count, 1 To UBound(arr, 2))
- n = 0
- For Each aa In d.items
- n = n + 1
- For j = 1 To UBound(arr, 2)
- crr(n, j) = arr(aa, j)
- Next
- Next
- End If
- With Worksheets("增减名单")
- .Cells.Clear
- If m > 0 Then
- With .Range("a1")
- .Value = "增加名单"
- .Resize(1, 6).Merge
- With .Font
- .Name = "黑体"
- .Size = 16
- End With
- End With
- .Range("a2").Resize(1, 6) = Array("学籍辅号", "班级", "座号", "姓名", "电话", "家长姓名")
- .Range("a3").Resize(m, UBound(drr, 2)) = drr
- .Range("a2").Resize(m + 1, UBound(drr, 2)).Borders.LineStyle = xlContinuous
- End If
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- If r > 1 Then
- r = r + 2
- End If
- If n > 0 Then
- With .Cells(r, 1)
- .Value = "减少名单"
- .Resize(1, 6).Merge
- With .Font
- .Name = "黑体"
- .Size = 16
- End With
- End With
- .Cells(r + 1, 1).Resize(1, 6) = Array("学籍辅号", "班级", "座号", "姓名", "电话", "家长姓名")
- .Cells(r + 2, 1).Resize(n, UBound(crr, 2)) = crr
- .Cells(r + 1, 1).Resize(n + 1, UBound(crr, 2)).Borders.LineStyle = xlContinuous
- End If
-
- With .UsedRange
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- End Sub
复制代码 |
|