小编Mar*_*kus的帖子

VBA跳过循环?

以下代码确定行中的单元格是否包含单词"Done".如果是,则将该行复制到另一个标有"Log"的表格并从列表中删除.为什么以下循环可能会跳过标记为"完成"的某些行?

Sub LogAndDelete()

Dim r As Integer
Dim Emptyrow As Integer
r = 1
For r = 5 To 70
    If Cells(r, 15) = "Done" Then
        'copying the row marked "Done"
        rng = Range(Cells(r, 1), Cells(r, 7))

        'determining the next empty row on log sheet
        Emptyrow = _
        Application.WorksheetFunction.CountA(Worksheets("Log").Range("A:A")) + 1

        'Pasting onto log sheet
        Range(Worksheets("Log").Cells(Emptyrow, 2), Worksheets("Log").Cells(Emptyrow, 8)) _
        = rng

        'Adding the date removed from log sheet in column A
        Worksheets("Log").Cells(Emptyrow, 1) = Date

        'Removing row marked "done" …
Run Code Online (Sandbox Code Playgroud)

excel vba excel-vba

0
推荐指数
1
解决办法
766
查看次数

标签 统计

excel ×1

excel-vba ×1

vba ×1