Search column F and write a string of found locations in column G for each F cell
Option Explicit
Sub Macro1()
Dim PlacesList As Variant, _
TestBlock As Range, _
Descriptions As Long, _
LastBlock As Long, _
Results As String, _
Loc As Variant, _
t0 As Double, _
matches As Long
With Application
.ScreenUpdating = False
.EnableEvents = False
End With 'application
LastBlock = Cells(Rows.Count, "F").End(xlUp).Row
PlacesList = WorksheetFunction.Transpose(Range("places").Value)
t0 = Timer
For Each TestBlock In Range("F1").Resize(rowsize:=LastBlock)
'clear the holder string
Results = ""
'search for each possible place
For Each Loc In PlacesList
'check if it is followed by a space or period
If InStr(TestBlock, Loc & " ") > 0 Or InStr(TestBlock, Loc & ".") Then
matches = matches + 1
If InStr(Results, Loc) = 0 Then
'if found, append to the string
Results = Results & IIf(Results = "", "", ",") & Loc
End If
End If
Next Loc
'write the found locations to column G
TestBlock.Offset(columnoffset:=1).Value = Results
Next TestBlock
With Application
.ScreenUpdating = True
.EnableEvents = True
End With 'application
'report process time
MsgBox "Process took: " & Timer - t0 & IIf((Timer - t0) > 1, " secs ", " sec ") & vbCrLf & "with " & matches & " matches found"
End Sub
Bookmarks