|
本帖最后由 gwjkkkkk 于 2024-8-20 20:29 编辑
Option Explicit
Sub TEST6()
Dim ar, br, i&, j&, n&, iPosCol&, dic As Object, strFileName$
With Worksheets(1).[F2]
If .Value = Empty Then MsgBox "时间为空", vbCritical: Exit Sub
strFileName = Format(.Value, "yyyy年m月d")
End With
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set dic = CreateObject("Scripting.Dictionary")
ar = Worksheets("所有人员名单").[A1].CurrentRegion.Value
For i = 2 To UBound(ar)
dic(ar(i, 1)) = Empty
Next i
ar = Worksheets(1).[C24:C28].Value
For i = 1 To UBound(ar)
br = Split(ar(i, 1), "、")
For j = 0 To UBound(br)
If dic.exists(br(j)) Then dic.Remove br(j)
Next j
Next i
ar = dic.keys: n = dic.Count
ar = transArrToCol(ar, 20, 0, UBound(ar))
Worksheets(1).Copy
With ActiveWorkbook
With .Worksheets(1)
ReDim br(1 To UBound(ar), 0)
For j = 1 To UBound(ar, 2)
iPosCol = j * 2
For i = 1 To UBound(ar)
br(i, 0) = ar(i, j)
Next i
.Cells(4, iPosCol).Resize(20) = br
Next j
End With
.SaveAs ThisWorkbook.Path & "\" & strFileName
.Close
End With
Set dic = Nothing
Application.ScreenUpdating = True
Application.DisplayAlerts = True
MsgBox "共填充" & n & "个姓名", vbInformation
Beep
End Sub
Function transArrToCol(ByVal ar, ByVal iCutNum&, _
ByVal iStartCol&, ByVal iEndCol&) As Variant()
Dim br, j&, n&, y&, x&, iRowSize&
If iStartCol < LBound(ar) Then iStartCol = LBound(ar)
If iEndCol > UBound(ar) Then iEndCol = UBound(ar)
n = -(Int(-(iEndCol - iStartCol + 1) / iCutNum))
iRowSize = IIf(iEndCol - iStartCol + 1 < iCutNum, iEndCol - iStartCol + 1, iCutNum)
ReDim br(1 To iRowSize, 1 To n)
n = 0
For j = iStartCol To iEndCol
n = n + 1
x = -Int(-n / iCutNum)
y = IIf(n Mod iCutNum = 0, iCutNum, n Mod iCutNum)
br(y, x) = ar(j)
Next j
transArrToCol = br
End Function
|
|