|
Option Explicit
Sub TEST1()
Dim ar, br, cr, i&, j&, m&, n&, tRng As Range, iMsg&, dic As Object, vKey
Application.ScreenUpdating = False
ar = Worksheets("名单").[A1].CurrentRegion.Value
Set dic = CreateObject("Scripting.Dictionary")
For i = 2 To UBound(ar)
dic(ar(i, 2)) = dic(ar(i, 2)) & " " & i
Next i
For Each vKey In dic.keys
cr = Split(dic(vKey))
ReDim br(1 To UBound(cr), 1 To 18)
For i = 1 To UBound(cr)
br(i, 1) = i: br(i, 2) = ar(cr(i), 3)
Next i
dic(vKey) = br
Next
Set tRng = Worksheets("记录样表").[A1:R4]
ar = Worksheets("字典").[A1].CurrentRegion.Value
With Worksheets("需求效果")
.Cells.Delete
For Each vKey In dic.keys
m = m + 1
n = .Cells(.Rows.Count, "A").End(xlUp).Row
n = IIf(n = 1, n, n + 2)
rngCopyToSame tRng, .Cells(n, 1)
With .Cells(n, 1)
.Cells(2, 3).Value = vKey
For i = 2 To UBound(ar)
If ar(i, 1) = vKey Then .Cells(2, 14).Value = ar(i, 2): Exit For
Next i
End With
If m > 1 Then .HPageBreaks.Add Before:=.Cells(n, 1)
With .Cells(n + 4, 1)
br = dic(vKey)
With .Resize(UBound(br), UBound(br, 2))
.Value = br
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Borders.LineStyle = xlContinuous
End With
End With
Next
.Activate
iMsg = MsgBox("是否预览", vbYesNo + vbInformation, "???")
If iMsg = vbYes Then .PrintPreview
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
|
评分
-
1
查看全部评分
-
|