|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
原始数据排列有序,不用字典也行。
- Sub test2()
- Dim r%, i%
- Dim arr, brr, zrr()
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- With Worksheets("总表")
- r = .Cells(.Rows.Count, 27).End(xlUp).Row
- arr = .Range("aa1:aa" & r)
- xm = ""
- m = 0
- For i = 10 To UBound(arr)
- If arr(i, 1) <> xm Then
- m = m + 1
- ReDim Preserve zrr(1 To 2, 1 To m)
- zrr(1, m) = i
- zrr(2, m) = i
- xm = arr(i, 1)
- Else
- zrr(2, m) = i
- End If
- Next
- End With
- For k = 1 To UBound(zrr, 2)
- With Worksheets("模板")
- .Range("d3,f3,l3,a10:ad21") = ""
- Worksheets("总表").Cells(zrr(1, k), 1).Resize(zrr(2, k) - zrr(1, k) + 1, 30).Copy .Range("a10")
- .Range("d3") = "户编号:" & .Range("ad10")
- .Range("f3") = "户主姓名:" & .Range("b10")
- .Range("l3") = "组别:" & .Range("z10")
- wjm = .Range("aa10")
- .Copy
- End With
- With ActiveWorkbook
- With .Worksheets(1)
- .Name = wjm
- End With
- .SaveAs Filename:=ThisWorkbook.Path & "" & wjm
- .Close False
- End With
- Next
- End Sub
复制代码 |
评分
-
2
查看全部评分
-
|