|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub TEST()
Dim arr, brr, iNum, i&, iTimes&, R&, t#
Application.ScreenUpdating = False
t = Timer
arr = [a1].CurrentRegion
iNum = InputBox("请输入行数", "行数", "200")
If iNum = "" Then Exit Sub
iTimes = -Int(-UBound(arr) / Val(iNum))
arr = cutArray(arr, Val(iNum))
ReDim brr(1 To Val(iNum), 1 To iTimes)
For i = 1 To UBound(arr)
For j = 1 To UBound(arr(i))
brr(j, i) = arr(i)(j, 1)
Next j
Next i
[C1].CurrentRegion.Clear
[C1].Resize(UBound(brr), UBound(brr, 2)) = brr
Application.ScreenUpdating = True
MsgBox "执行完毕!_用时: " & Format(Timer - t, "0.00") & " 秒", 64
End Sub
Function cutArray(ar, iCutNum&) As Variant
Dim brr(), crr, i&, j&, iPosRow&, R&, k&
For i = 1 To UBound(ar) Step iCutNum
iPosRow = IIf((i + iCutNum - 1) > UBound(ar), UBound(ar) Mod iCutNum, iCutNum)
ReDim crr(1 To iPosRow, 1 To UBound(ar, 2))
For j = 1 To UBound(crr)
For k = 1 To UBound(crr, 2)
crr(j, k) = ar(i - 1 + j, k)
Next k
Next j
R = R + 1
ReDim Preserve brr(1 To R)
brr(R) = crr
Next i
cutArray = brr
End Function
|
评分
-
1
查看全部评分
-
|