1 Attachment(s)
Searching for multiple texts within a cell (InStr)
Hi All,
What am I doing wrong here?
The IF statement works but I cant get the elseif statement to work where I want to check for multiple words within the cell?
Many thanks :)
Code:
Option Compare Text
Sub Test()
Dim lastrow As Long
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
For i = 1 To lastrow
If InStr(Range("A" & i).Value, "Red") > 0 Then
Range("C" & i).FormulaR1C1 = "Correct"
ElseIf InStr(Range("A" & i).Value, "Blue") > 0 And InStr(Range("A" & i).Value, "Green") > 0 Then
Range("C" & i).Value = "Correct"
Else
'xxxxxx
End If
Next
End Sub