|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Explicit
Sub TEST2()
Dim ar, br(), cr, i&, j&, k&, n&, r&, Rng As Range
Application.ScreenUpdating = False
With Worksheets("明细").[A1].CurrentRegion
ar = .Value
For i = 2 To UBound(ar)
If Len(ar(i, 1)) Then
r = r + 1
ReDim Preserve br(1 To 2, 1 To r)
br(1, r) = i
End If
Next i
For j = 1 To UBound(br, 2)
If j = UBound(br, 2) Then
br(2, j) = .Cells(br(1, j), 1).Resize(UBound(ar) - br(1, j) + 1).Resize(, UBound(ar, 2))
Else
br(2, j) = .Cells(br(1, j), 1).Resize(br(1, j + 1) - br(1, j)).Resize(, UBound(ar, 2))
End If
Next j
ar = Array(1, 2, 3, 7, 9, 10, 11)
For k = 1 To UBound(br, 2)
ReDim cr(1 To 5, 1 To 11)
For i = 1 To UBound(br(2, k))
For j = 0 To UBound(ar)
cr(i, ar(j)) = br(2, k)(i, j + 16)
Next j
Next i
br(1, k) = cr
Next k
End With
Set Rng = Worksheets("模板").[A1:L12]
ar = [{"B2","D2","F2","H2","J2","L2","B3","E3","H3","J3","L3","C4","E4","I4","K4"}]
With Worksheets("样例")
.Cells.Delete
For i = 1 To UBound(br, 2)
n = (i - 1) * 13 + 1
With .Cells(n, 1)
rngCopyToSame Rng, .Range("A1")
.Range("A1") = "失业人员就业帮扶记录(" & i & ")号"
For j = 1 To UBound(ar)
.Range(ar(j)).Value = br(2, i)(1, j)
Next j
.Range("A8").Resize(UBound(br(1, i)), UBound(br(1, i), 2)) = br(1, i)
End With
Next i
.Activate
End With
Application.ScreenUpdating = True
Beep
End Sub
Function rngCopyToSame(ByVal rngSel As Range, ByVal rngTarget As Range)
Dim i&
rngSel.Copy
rngTarget.PasteSpecial xlPasteColumnWidths
rngSel.Copy rngTarget
With rngTarget.Resize(rngSel.Rows.Count, rngSel.Columns.Count)
For i = 1 To .Rows.Count
.Rows(i).RowHeight = rngSel.Rows(i).RowHeight
Next i
End With
End Function
|
|