In my code i want to use if condition. In which i want to use "OR" around 18 times. Like for e.g.
If a="something" or a="something" or a="something" or.........(up to 18 times)... then
'do nothing
else
'do action
end if
[Note : value of a is changing in For loop every time] so i just want to ask does there any limitation in IF for using OR in limited times. OR is there any other better way to do the same.
Thanks
Use the line-continuation character, which is an underscore ( _ ), at the point at which you want the line to break. The underscore must be immediately preceded by a space and immediately followed by a line terminator (carriage return) or (starting with version 16.0) a comment followed by a carriage return.
Wrap Text to a Cell using VBADefine the cell where you want to apply the wrap text using the range property. Type a dot to see the list of the properties and methods for that cell. Select the “WrapText” property from the list. Enter the equals sign “=” and the type TRUE to turn the wrap text ON.
As far as I know, there is no limitation when using OR
this way.
Yet, you may consider alternative ways of coding this.
First, if you do nothing
in the first case, then consider using the Not
statement:
If Not True Then
'do somethin
'no else
End If
Second, if you are checking the very same variable, you could either consider using a Select Case
but it doesn't seem appropriate in your case if you have only one case.
Eventually, if you are checking strings, you could probably better use a search within an array (with Application.Match
if you are within Excel or .Contains
) or within a String using Instr
.
[EDIT] Another very good way to handle this would be to use the Dictionary Structure of VBA and check if a
exists (see MSDN for some information).
This answer is just an elaboration on my comments to JMay, full credit to him. I think the original poster meant to the "Something" in his question differ, with a
being the loop variable.
For each a in MyList
Select Case a
Case "something", "something2", "something3", "something4", "something5", _
"something6", "something7", "something8", "something9", "something10", _
"something11", "something12", "something13", "something14", "something15", _
"something16", "something17", "something18"
'DO NOTHING
Case Else
'do-something code goes here
' and here
' and here
' and here
End Select
Next a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With