我發現,直接應用到,我想在這裏Excel VBA: Loop through cells and copy values to another workbook構建代碼的線程。使用的IsEmpty停止循環
Sub test()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim CurCell_1 As Range, CurCell_2 As Range
Dim Ran As Range
Dim Group As Range, Mat As Range
Application.ScreenUpdating = True
Set ws1 = ActiveWorkbook.Sheets("Scrap")
Set ws2 = ActiveWorkbook.Sheets("FC Detail")
For Each Mat In ws1.Range("E:E")
Set CurCell_2 = ws2.Range("F8")
For Each Group In ws1.Range("E:E")
Set CurCell_1 = ws1.Cells(Group.Row, Mat.Column)
If Not IsEmpty(CurCell_2) Then
CurCell_2.Value = CurCell_1.Value
End If
Next
Next
End Sub
此代碼有一個例外,它不斷循環。
我認爲If Not IsEmpty
將是描述符VBA,一旦到達列表的末尾停止該程序。
你是什麼意思的「循環不斷?」如果代碼從不退出循環,你怎麼知道代碼「有效」? – 2012-07-10 22:39:45
它正在連續運行,因爲您正在處理整個列......兩次。爲什麼不找到最後一行然後限制你的範圍,如其他鏈接所示? – 2012-07-10 23:13:51