下面是打印列表的部分到電子表格的方法。
Option Explicit
'this generates the list and I need to create an array from this list for different sizes of n
Sub SetUpList()
Dim UnsortedList(1 To 100000, 1 To 1) As Double
Dim i As Long, N As Long
Dim A As Variant, R As Range
For i = 1 To 100000
UnsortedList(i, 1) = Rnd(-i)
Next i
Range("A1:A100000").Value = UnsortedList
N = Cells(2, 2).Value
'this allows us to determine the size of the array which will vary because there can be different sizes of n
Initialize
End Sub
Sub Initialize()
Dim rDest As Range
Dim i As Long, N As Long
Dim A As Variant
Dim UnsortedList As Variant
UnsortedList = Range("A1", Cells(Rows.Count, "A").End(xlUp))
N = Cells(2, 2)
Set rDest = Range("C1")
ReDim A(1 To N, 1 To 1)
For i = 1 To N
A(i, 1) = UnsortedList(i, 1)
Next i
Set rDest = rDest.Resize(rowsize:=N)
rDest.EntireColumn.Clear
rDest = A
End Sub
爲什麼不按照需要調整'範圍'的大小,然後將所有值一次拉入數組? – Comintern
歡迎來到StackOverflow!請訪問該頁面:[如何提出一個很好的問題](http://stackoverflow.com/help/how-to-ask),因爲你的文章沒有描述這個問題,而且這裏也沒有提出明確的問題。 –
你的問題是什麼?您想做什麼? –