|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test()
- Dim r&, i&
- Dim arr, brr
- Dim d As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- tt = Timer
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("数据库原表")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:e" & r)
- End With
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 1)) Then
- m = 1
- ReDim brr(1 To 5, 1 To m)
- Else
- brr = d(arr(i, 1))
- m = UBound(brr, 2) + 1
- ReDim Preserve brr(1 To 5, 1 To m)
- End If
- If arr(i, 2) = "户主" Then
- For j = 1 To 5
- brr(j, m) = brr(j, 1)
- brr(j, 1) = arr(i, j)
- Next
- Else
- For j = 1 To 5
- brr(j, m) = arr(i, j)
- Next
- End If
- d(arr(i, 1)) = brr
- Next
- ReDim crr(1 To UBound(arr), 1 To 5)
- m = 1
- For Each aa In d.keys
- brr = d(aa)
- crr(m, 1) = brr(5, 1)
- crr(m, 2) = brr(3, 1)
- crr(m, 3) = brr(4, 1)
- If UBound(brr, 2) > 1 Then
- For j = 2 To UBound(brr, 2)
- crr(m, 4) = brr(3, j)
- crr(m, 5) = brr(4, j)
- m = m + 1
- Next
- Else
- m = m + 1
- End If
- Next
- With Worksheets("转换后生成的表")
- .UsedRange.Offset(2, 0).ClearContents
- .Range("a3").Resize(m, UBound(crr, 2)) = crr
- .Range("a1:e" & m + 1).Borders.LineStyle = xlContinuous
- End With
- Application.ScreenUpdating = True
- MsgBox "数据整理完毕!共用时" & Timer - tt & "秒"
- End Sub
复制代码 |
评分
-
2
查看全部评分
-
|