Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IN syntax 1

Status
Not open for further replies.

dgillz

Instructor
Mar 2, 2001
10,045
US
I cannot get microsoft VBA to recognize this statement:

if cells(irow,21).value in ("Y","N","R","P") then....

I have tried the IN statement with and without parens. I know this is a simple syntax issue but I cannot find an example of how to do this, even in VBA help.

Any insights?

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports

"What version of URGENT!!! are you using?
 
I haven't encountered such usage of IN, except in SQL.

But do try the Like operator, for instance if the cell contains only one character and you want it verified against your list

[tt]if cells(irow,21).value Like "[YNRP]" then....[/tt]

check it out in the help file

Or perhaps the Select Case

[tt]Select Case cells(irow,21).value
Case "Y","N","R","P"
....
Case Else
End Select[/tt]

But with more information about what you want to do, we might even help solving the issue.

Roy-Vidar
 
Select case sounds good to me. Thanks.

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports

"What version of URGENT!!! are you using?
 
I don't think IN is a valid VBA expression or operator.

Maybe you were thinking of InStr? (which wouldn't work for what you are trying to do.)

 
I am somewhat new to VBA, I definitely had my SQL hat on for that one.

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports

"What version of URGENT!!! are you using?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top