2
votes

I am trying to create a Do While loop with an if statement in bedded within it. Depending on the TRUE/FALSE value of the If statement, it could either enter into another (sub) Do While loop or just loop around back to the first one and start all over again.

My problem is that once the If statement returns a "TRUE" value, the macro executes the result but then stops the 1st overlying Do While loop that I want to continue. (Basically it does not generate another loop for x+1 once there is a TRUE value in the If Statement)

Thank you ahead of time for your help

'x is row in input tab
Dim x As Integer
'z is column in input tab
Dim z As Integer

x = 9
Do While x < 59
If Sheets("Input Tool (Auction Team)").Cells(x, "C") = "N" And Cells(x, "D") = "Yes" Then

    'insert row and add values
    Sheets("Round Results (Auction Team)").Range("C13").EntireRow.Insert
    z = 5

    Do While z < 19

    Sheets("Input Tool (Auction Team)").Cells(x, z).Copy
    Sheets("Round Results (Auction Team)").Cells(13, z - 2).PasteSpecial Paste:=xlPasteValues
    Sheets("Round Results (Auction Team)").Cells(14, z - 2).Copy
    Sheets("Round Results (Auction Team)").Cells(13, z - 2).PasteSpecial Paste:=xlPasteFormats
    Sheets("Round Results (Auction Team)").Cells(14, 2).Copy Cells(13, 2)

    z = z + 1

    Loop                  
Else 
End If
x = x + 1
Loop
End Sub
1
One thing I see as a potential problem is the unqualified Cells(x, "D") statement. Place the worksheet in front of it like this: Sheets("Input Tool (Auction Team)").Cells(x,"D"), whatever specific sheet you want to refer to. Leaving it as makes it refer to whatever sheet is active at the time the code runs, which may not be want what you desire. - Scott Holtzman
Awesome. That was it. Appreciate your help - Rob Anderson
@Scott Holtzman kindly put the answer in the answer tab. So we can remove this Q from SO unanswered list. (: - p._phidot_
@p._phidot_ - done - Scott Holtzman

1 Answers

1
votes

Qualify the unqualified object references with their parent.

For example, I see 'Cells(x, "D")'. Qualify that range to the parent worksheet like so:

Sheets("Input Tool (Auction Team)").Cells(x,"D")