none
Do loop while not empty - not working RRS feed

  • Question

  • Hi Guys, 

    Hope you are well, i'm really struggling with a loop. I cant seem to understand why its not working. Its return the first value, but that's it. Its supposed to be carrying on looping until the value in column A is empty. 

    Appreciate any help I can get in this. 

    Thanks Chaz

    The code is: 

    Dim i As Long  '' for looping through the whole list

    i = 7   

    Do While Worksheets("sales").Range("A" & i) <> ""

        

     If Worksheets("sales").Range("P" & i) = Worksheets("Sheet1").Range("A" & j) Then
        Worksheets("cost").Range("M" & j) = Worksheets("sales").Range("E" & i)
     End If   

    i = i + 1
    Loop
    End Sub

    Sunday, October 6, 2013 4:16 PM

Answers

  • But then, j will remain equal to 3 throughout the loop, so Worksheets("cost").Range("M" & j) will be the same cell all the time (namely, cell M3).

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by Chaz1010 Tuesday, October 8, 2013 11:17 AM
    Sunday, October 6, 2013 9:31 PM

All replies

  • What is the variable j ? It is neither declared, nor assigned a value within the code that you posted.

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Sunday, October 6, 2013 7:48 PM
  • hi. i missed the code. The below code should have been added. It references the position on another spreadsheet. Thanks

    DIM j as long

    i = 3


    Sunday, October 6, 2013 8:52 PM
  • *j = 3
    Sunday, October 6, 2013 9:25 PM
  • But then, j will remain equal to 3 throughout the loop, so Worksheets("cost").Range("M" & j) will be the same cell all the time (namely, cell M3).

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by Chaz1010 Tuesday, October 8, 2013 11:17 AM
    Sunday, October 6, 2013 9:31 PM