|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("村级协管员信息汇总表")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:j" & r)
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 1)) Then
- m = 1
- ReDim brr(1 To 9, 1 To m)
- Else
- brr = d(arr(i, 1))
- m = UBound(brr, 2) + 1
- ReDim Preserve brr(1 To 9, 1 To m)
- End If
- For j = 2 To UBound(arr, 2)
- brr(j - 1, m) = arr(i, j)
- Next
- d(arr(i, 1)) = brr
- Next
- End With
- k = 0
- For Each aa In d.keys
- k = k + 1
- arr = d(aa)
- ReDim brr(1 To UBound(arr, 2), 1 To UBound(arr))
- For i = 1 To UBound(arr)
- For j = 1 To UBound(arr, 2)
- brr(j, i) = arr(i, j)
- Next
- Next
- With Worksheets("模板")
- .Range("a8:i" & .Rows.Count).Clear
- .Range("d5") = aa
- .Range("a8").Resize(UBound(brr), UBound(brr, 2)) = brr
- r = UBound(brr) + 7
- .Range("a7:i" & r).Borders.LineStyle = xlContinuous
- With .UsedRange
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- .Copy
- End With
- With ActiveWorkbook
- .SaveAs Filename:=ThisWorkbook.Path & "" & aa
- .Close False
- End With
- If k = 2 Then
- Exit For
- End If
- Next
- Application.ScreenUpdating = True
- MsgBox "数据拆分完毕!"
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|