Vba 当单元格为空时,我需要帮助退出循环

Vba 当单元格为空时,我需要帮助退出循环,vba,loops,Vba,Loops,这是我目前的代码。它很好地循环并输入我需要的数据,但它不会在我希望它停止时停止。当发现B列中的单元格为空时,我需要它停止 Sub Insert_Tasks_Info() ' ' Insert_Tasks_Info Macro ' Dim counter As Integer counter = 4 'runs macor until first empty cell in Column "B" Do Until ThisWorkboo

这是我目前的代码。它很好地循环并输入我需要的数据,但它不会在我希望它停止时停止。当发现B列中的单元格为空时,我需要它停止

Sub Insert_Tasks_Info()
    '
    ' Insert_Tasks_Info Macro
    '

    Dim counter As Integer
    counter = 4

    'runs macor until first empty cell in Column "B"

    Do Until ThisWorkbook.Sheets("Data").Cells(counter, 2).Value = ""

        'copies order task info and pastes into data tab

        Sheets("Template").Select
        Range("A4:G9").Select
        Selection.Copy
        Sheets("Data").Select
        Range("A3").Select
        Selection.End(xlDown).Select
        NextFree = Range("A3:A" & Rows.Count).Cells.SpecialCells(xlCellTypeBlanks).Row
        Range("A" & NextFree).Select
        Selection.Insert Shift:=xlDown

        'copies hours info and pastes into data tab

        Sheets("Template").Select
        Range("F3:AA9").Select
        Application.CutCopyMode = False
        Selection.Copy
        Sheets("Data").Select
        Range("F2").Select
        Selection.End(xlDown).Select
        NextFree = Range("F2:F" & Rows.Count).Cells.SpecialCells(xlCellTypeBlanks).Row
        Range("F" & NextFree).Select
        ActiveSheet.Paste

        Call Insert_Zone

        counter = counter + 1

    Loop

End Sub
有关如何查找该列中的最后一行,请参见。然后将计数器=4的
循环到最后一行,而不是当前的
Do
循环。另请参阅。