|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Dim rng As Range
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(2, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a1:a" & r)
- For i = 3 To UBound(arr)
- If Not d.exists(arr(i, 1)) Then
- Set d(arr(i, 1)) = .Range("a1").Resize(2, c)
- End If
- Set d(arr(i, 1)) = Union(d(arr(i, 1)), .Cells(i, 1).Resize(1, c))
- Next
- End With
- With Worksheets("模板")
- For Each aa In d.keys
- .Cells.Clear
- d(aa).Copy .Range("a1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a1").Resize(r, c)
- d1.RemoveAll
- For j = 3 To UBound(arr, 2)
- If Application.Count(Application.Index(arr, 0, j)) <> 0 Then
- d1(j) = ""
- End If
- Next
- d1(c) = ""
- n = 3
- Do While d1.Count < 3
- d1(n) = ""
- n = n + 1
- Loop
- Set rng = .Columns(c + 1)
- For j = 3 To c
- If Not d1.exists(j) Then
- Set rng = Union(rng, .Columns(j))
- End If
- Next
- rng.Delete
- .PrintOut
- Next
- End With
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|