返回列表 上一主題 發帖

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

回復 8# EGBT


     動態陣列 Redim Student(x)這樣寫時,當重新一次的Redim時會把原來在陣列的值清空
所以當然沒值給它顯示啊迴圈中的重新定維數又不希望清空值必須寫成
ReDim Preserve Student(x)

TOP

回復 8# EGBT


    一般使用陣列不應該Sheets("統計").Cells(x, 1) = Student(x)這樣子寫
這樣寫只是浪費了陣列執行速度的優點
最好是迴圈跑完後再貼到儲存格
如下
  1. Sub TEST1()
  2. Dim Student()
  3. x = 0
  4. With Sheets("學生頁")
  5.     For Each y In .Range(.Cells(2, 1), .Cells(.Cells(Rows.Count, 1).End(xlUp).Row, 1))
  6.         ReDim Preserve Student(x)
  7.         Student(x) = y
  8.         x = x + 1
  9.     Next
  10. End With
  11. Sheets("統計").Cells(1, 1).Resize(UBound(Student) + 1) = Application.Transpose(Student)
  12. End Sub
複製代碼

TOP

回復 10# ikboy


感謝

TOP

回復 1# EGBT

試試看這個適不適合
  1. Sub test1()
  2.     Dim student
  3.     Sheets("學生頁").Select
  4.     student = Range(Cells(2, 1), Cells(Cells(Rows.Count, 1).End(xlUp).Row, 1))
  5.     Sheets("統計").Cells(2, 1).Resize(UBound(student)) = student
  6.    
  7. End Sub
複製代碼

TOP

回復 9# lpk187


    樓上大大完全了解我...完全正解~太感謝你了^.^

TOP

        靜思自在 : 君子如水,隨方就圓,無處不自在。
返回列表 上一主題