|
Option Explicit
Sub TEST1()
Dim ar, br, i&, j&, r&, iTimes&
iTimes = Application.InputBox("请选择随机行数", Title:="提示", Default:=6, Type:=1)
If iTimes = 0 Then Exit Sub
Application.ScreenUpdating = False
With Sheets(1)
ar = Range(.[A1], .Cells(Rows.Count, "A").End(xlUp)).Value
ReDim br(1 To UBound(ar) * iTimes)
For i = 1 To UBound(ar)
For j = 1 To iTimes
r = r + 1
br(r) = ar(i, 1)
Next j
Next i
End With
ar = oneToTwoDim(br, 12)
Cells.Delete
With [A1].Resize(UBound(ar), UBound(ar, 2))
.Value = ar
With .Font
.Name = "楷体"
.Size = 39
.Bold = True
.ThemeColor = 3
End With
End With
Application.ScreenUpdating = True
Beep
End Sub
Function oneToTwoDim(ByVal ar, ByVal iColSize&)
Dim vResult, i&, y&, x&, iRowSize&
iRowSize& = -Int(-UBound(ar) / iColSize)
ReDim vResult(1 To iRowSize, 1 To iColSize)
For i = 1 To UBound(ar)
y = -Int(-i / iColSize)
x = IIf(i Mod iColSize = 0, iColSize, i Mod iColSize)
vResult(y, x) = ar(i)
Next i
oneToTwoDim = vResult
End Function
|
|