返回列表 上一主題 發帖

這個問題頭大了..想了好久

其實你代碼就等如:
Sub zz()
With Sheets("汜?")
    .Range("a2:a" & .Cells(Rows.Count, 1).End(xlUp).Row).Copy Sheets("緙?").[a1]
End With
End Sub

下面我把你的代碼改為:
Sub TEST()
Dim arr   'Student()
With Sheets("學生頁")
    arr = .Range("a2:a" & .Cells(Rows.Count, 1).End(xlUp).Row)
End With
'x = 1
For Each y In arr
x = x + 1
'ReDim Student(x)
'Student(x) = y
Sheets("統計").Cells(x, 1) = y
Next
End Sub

TOP

首先你的動態陣列要保留數據,請用 Redim Preserve Student(x)
下面做了一個例子

Sub TEST()
Dim Student()
r = Sheets("學生頁").Cells(Rows.Count, 1).End(xlUp).Row
x = 1
For Each y In Sheets("學生頁").Range("a2:a" & r)
ReDim Preserve Student(x)
Student(x) = y
Sheets("統計").Cells(x, 1) = Student(x)
x = x + 1
Next
MsgBox Student(1)
MsgBox Student(11)
End Sub

TOP

        靜思自在 : 滴水成河。粒米成蘿,勿輕己靈,勿以善小而不為。
返回列表 上一主題