Chase Flint
Chase Flint

Reputation: 45

Do until____or until____ loop

How do I make two conditions for a loop?

Essentially I want to do the following:

Sub SubMac4_1Loop()

    Do Until ActiveCell.Value = "X"
    **or until ActiveCell.Offset(1,1) = ""**
        Selection.EntireRow.Delete
Loop
End Sub

Obviously this won't work, but I need to know how to accomplish this.

Upvotes: 1

Views: 55

Answers (1)

user4039065
user4039065

Reputation:

You are looking for an OR boolean condition.

Do Until ActiveCell.Value = "X" OR ActiveCell.Offset(1,1) = ""
    Selection.EntireRow.Delete
Loop

More information on VBA's Do [Until]/[While] Loop syntax is available from the MSDN site at Do...Loop Statement.

See How to avoid using Select in Excel VBA macros for methods on getting away from relying on select and activate to accomplish your goals.

Upvotes: 5

Related Questions