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

        x = x + 1

 Loop

In the above VBA code slice, I get a Run-time error '13': Type mismatch. stringOne is declared a String. I can eliminate Or "" and the loop works. I can eliminate stringOne and only have "" and the loop works. Only when I add the Or "" does the loop stop functioning. I've even swapped order, i.e, = "" Or stringOne. Any thoughts?

3
  • 4
    It usually helps get answers if you include a tag for the language you're using. I'm suspecting either VBA or VB.Net, but it would help greatly if you would edit to include the proper language tag.
    – Ken White
    Jul 8, 2014 at 13:36
  • 1
    Why downvote OPs Q? It is a valid question and at least two people did understand it an posted a solution worth a +1 ? Jul 8, 2014 at 13:51
  • Thank you Ken. Sorry, I am new to the forum as a poster and thought I had everything together. I edited to add VBA. I have worked on this one line of code for more than a full day and decided I needed outside help. I'm not sure why it's worth downvoting...my apologies for the offense. Please let me know what caused the downvote so I can learn from the mistake. Thanks!
    – KeithG
    Jul 8, 2014 at 14:02

2 Answers 2

11

Any condition needs expressions and operators.

 Do until exp1 op exp2 OR exp3

might only be valid if exp3 is a boolean type. "" (String) is not.

So it should be like

 Do Until Sheets("Sheet1").Cells(x, y).Value = stringOne Or Sheets("Sheet1").Cells(x, y).Value = ""
1
  • Works perfectly Axel! Thanks for the explanation. You have taught me something new today!
    – KeithG
    Jul 8, 2014 at 14:05
5

You need a boolean operation after the OR, so you basically need:

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

        x = x + 1

 Loop

Or "" is not a boolean operation, and therefore you have Do Until (boolean operation) OR (string constant) instead of Do Until (boolean operation) OR (boolean operation)

1
  • Thanks Allan! I have no formal training in VBA and only learned out of necessity, so I am not familiar with the rules of the language, but it really helps me to know Or will require a boolean operation rather than a string. I'd upvote yours and Axel's responses, but I don't have any rep yet. You guys deserve the upvotes though!
    – KeithG
    Jul 8, 2014 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.