VBA Do before loop with condition ""

 Do Until Sheets("Sheet1").Cells(x, y).Value = stringOne Or ""

        x = x + 1

 Loop

In the above VBA code snippet, I get a runtime error of "13": type of mismatch. stringOne is declared String. I can exclude "or" and the loop works. I can exclude stringOne and have only "and the loop works. Only when I add" Or "does the loop stop working. I even changed the order, ie =" "Or stringOne. Any thoughts?

+4
source share
2 answers

Any condition needs expressions and operators.

 Do until exp1 op exp2 OR exp3

can only be valid if it exp3is a Boolean type. "" (String) no.

So it should be like

 Do Until Sheets("Sheet1").Cells(x, y).Value = stringOne Or Sheets("Sheet1").Cells(x, y).Value = ""
+10

OR, :

Do Until Sheets("Sheet1").Cells(x, y).Value = stringOne Or Sheets("Sheet1").Cells(x, y).Value = ""

        x = x + 1

 Loop

"" , Do Until (boolean operation) OR (string constant) Do Until (boolean operation) OR (boolean operation)

+5

Source: https://habr.com/ru/post/1547595/


All Articles