1

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.

pnuts
  • 58,317
  • 11
  • 87
  • 139
Chase Flint
  • 45
  • 1
  • 3

1 Answers1

5

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.

Community
  • 1
  • 1
  • 3
    I love how you link to that question (avoid select/activate) in pretty much every answer I see you post ;-) – Mathieu Guindon Oct 29 '15 at 21:23
  • This one is particularly important as the user is relying on the [ActiveCell property](https://msdn.microsoft.com/en-us/library/office/ff193314.aspx) to shift as rows are deleted. Not a 'best practice' in my estimation. There are so many things that could go wrong you might as well be programming Word VBA (ewww!). –  Oct 29 '15 at 21:26