slomo
slomo

Reputation: 117

How to set "or" in VBA in excel

I set "if" with the "or" condition and give an error

If textbox1.Text = "abc def" Or "def" Then

I understand that I'm not writing right? What is my problem?

Upvotes: 1

Views: 64

Answers (2)

Chris Melville
Chris Melville

Reputation: 1518

If you have many conditions, use Select Case:

Select Case textbox1.Text
    Case “abc def”, “def”, “xyz”
        MsgBox “Note that multiple values may be captured here, separated by commas”
    Case “abc”
        MsgBox “Just abc”
    Case Else
        MsgBox “Everything else”
End Select

Upvotes: 3

urdearboy
urdearboy

Reputation: 14580

You need to restate the test object

If textbox1.Text = "abc def" Or textbox1.Text = "def" Then

Upvotes: 2

Related Questions