0

Here is my current code. It loops fine and enters the data I need but it does not stop when I would like it to. I need it to stop when it the cell in column B is found to be blank.

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
K.Dᴀᴠɪs
  • 9,945
  • 11
  • 33
  • 43
  • 2
    See [this question](https://stackoverflow.com/questions/11169445/error-in-finding-last-used-cell-in-excel-with-vba) for how to find the last row in that column. Then loop `For counter = 4 to lastRow` instead of your current `Do` loop. – BigBen Sep 25 '19 at 19:06
  • 1
    Also see [How to avoid Select](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba). – BigBen Sep 25 '19 at 19:06

0 Answers0