基于Activecell值未停止的Excel VBA循环

时间:2017-09-07 08:56:45

标签: excel vba excel-vba

我有一个循环,需要在activecell值为" BBSE"时停止,但是它会通过单元并继续循环。有人可以帮我吗? 我在一个workbbok中从表中剪切行并将其粘贴到另一个workbbok中。在F列中的列表之前,我有许多空白单元格,因此我使用了xldown。 以下是相关代码:

'Illuminators Worksheet
OP_wb.Activate
Range("F2").End(xlDown).Select


Do Until ActiveCell.Value = "BBSE"
    OP_wb.Activate
    Worksheets("Optic Main").Activate
    Range("F2").End(xlDown).Select
    Selection.EntireRow.Cut
    Demand_WB.Activate
    Worksheets("Illuminators").Activate
    Range("A" & Rows.Count).End(xlUp).Offset(1).Select
    ActiveSheet.Paste


Loop

这是我想要在红圈中停止循环的地方:

enter image description here

这就是我使用END.xlDown

的原因

enter image description here

2 个答案:

答案 0 :(得分:1)

如果我理解你想要正确实现的目标,我相信以下内容将会实现:

public writeFile(subPath: string, contents: string | Object) {

      if(!contents) {
         contents = '';
      }

      const contentsAsString: string = typeof contents === 'object' ? 
                               JSON.stringify(contents) : contents.toString();      

      this.file.writeFile(this.path, subPath, contentsAsString);
}

答案 1 :(得分:0)

可以尝试这样......

'Mentioning Starting Row Here
x = 2

Do
    'x refers to Row and F refer to column name
    With Cells(x, "F")
        'Exiting Do Loop once it finds the matching value using If statement
        If .Value = "BBSE" Then Exit Do
        OP_wb.Activate
        Worksheets("Optic Main").Activate
        .EntireRow.Cut
        Demand_WB.Activate
        Worksheets("Illuminators").Activate
        Range("A" & Rows.Count).End(xlUp).Offset(1).Select
        ActiveSheet.Paste
    End With
    'Incrementing row number here to move on to next row
    x = x + 1
Loop