我发现,直接应用到,我想在这里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