Hi MrExcelers,
I have adapted this VBA that has been helpful with finding the first word included in a string within each cell in my sheet. However, if the word is in the middle of a string the word is not identify. I think the function "Instr" may help but I have been unable to adapt this function in the macro. You'll see that I have included the function "InStr" in the array (in bold) below but it is not working. I would appreciate much if any of you could assist please.
I have adapted this VBA that has been helpful with finding the first word included in a string within each cell in my sheet. However, if the word is in the middle of a string the word is not identify. I think the function "Instr" may help but I have been unable to adapt this function in the macro. You'll see that I have included the function "InStr" in the array (in bold) below but it is not working. I would appreciate much if any of you could assist please.
VBA Code:
Sub WordInAString()
Dim lr As Long
Dim arr
Dim r As Long
Dim i As Long
Dim x As String
Application.ScreenUpdating = False
[B]arr = Array("ABC", "10ABC", InStr(cell.Value, "ABC") > 0)[/B]
' Find last row with data in column A
lr = cells(Rows.Count, "A").End(xlUp).Row
' Loop through all rows from bottom to top
For r = lr To 1 Step -1
' Loop through each value in array and check for a match
For i = LBound(arr) To UBound(arr)
' Get value to look for
x = arr(i)
' Check for value
If Left(cells(r, "B"), Len(x)) = x Then
' If value found, write the category assigned
cells(r, "B").Offset(0, 7).Value = "Newtown Public School"
Exit For
End If
Next i
Next r
Application.ScreenUpdating = True
MsgBox "Macro complete!"
End Sub