Looping code through run

  • I need help looping the following code to run until there is no data in column 3. right now the code only travels through row 193.

  • Re: Looping code through run

    You could mod your code as follows to loop automatically through the last used row in column C. (I think you asked this question.)

    I don't see why your code is stopping at row 193. Looks like it should do row-counter = 194 also.

    Dim LstRow As Long
    LstRow = Cells(Rows.Count, 3).End(xlUp).Row
    For Row_counter = 7 To LstRow
  • Re: Looping code through run

    Hi, this is untested but as well as thomach's suggestion for finding the last row of data in column 3 I think you can reduce your code by not selecting the sheet and ranges.
    Sub dist()
    Dim shtInvSol As Worksheet
    Set shtInvSol = Sheets("Inverse Solution")
    With Sheets("Point File")
    .Range("C4:D4").Copy shtInvSol.Range("C3")
    .Range("E4:F4").Copy shtInvSol.Range("C4")

    For Row_counter = 7 To .Cells(.Rows.Count, 3).End(xlUp).Row
    Col_counter = 3
    .Cells(Row_counter, Col_counter).Copy shtInvSol.Range("G3")

    Col_counter = Col_counter + 1
    .Cells(Row_counter, Col_counter).Copy shtInvSol.Range("H3")

    Col_counter = Col_counter + 1
    .Cells(Row_counter, Col_counter).Copy shtInvSol.Range("G4")

    Col_counter = Col_counter + 1
    .Cells(Row_counter, Col_counter).Copy shtInvSol.Range("H4")

    Col_counter = Col_counter + 1
    .Cells(Row_counter, Col_counter).PasteSpecial Paste:=xlPasteValues, _
    Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Next Row_counter
    End With
    End Sub


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!