Prevost
Board Regular
- Joined
- Jan 23, 2014
- Messages
- 198
Hi There,
Is there a way in VBA to use an IF statement and have multiple checks? So for example if I wanted to check a cell value for one of several string segments, could I do that with one if statement? I could do multiple ELSEIF statements or multiple CASE statements, but I thought it would be easier to check all in one line and then only have to insert the resulting code once.
Thanks!
Is there a way in VBA to use an IF statement and have multiple checks? So for example if I wanted to check a cell value for one of several string segments, could I do that with one if statement? I could do multiple ELSEIF statements or multiple CASE statements, but I thought it would be easier to check all in one line and then only have to insert the resulting code once.
Thanks!
Code:
Sub MultipleIFs()
Dim A As String, B As String
A = "apple"
B = "banana"
If InStr(1, ActiveCell.Value, A) Or InStr(1, ActiveCell.Value, B) Then
'carry out some code
Else
End If
End Sub