Forum Discussion
How do I find multiple search terms in Excel?
- Apr 27, 2020
AbtinS I see my code only looks for cells which contain just the word you are looking for. This adjusted version looks for cells containing the words:
Option Explicit Sub ListHits() Dim Cell2Find As Range Dim FoundCell As Range Dim FirstFound As Range Dim Ct As Long Dim KeepLooking As Boolean For Each Cell2Find In Worksheets("Keywords").UsedRange If Len(Cell2Find.Value) > 0 Then Set FirstFound = Nothing With Worksheets("Data") Ct = 0 Set FoundCell = Nothing Set FoundCell = .UsedRange.Find(What:=Cell2Find.Value, After:=.Range("A1"), LookIn:=xlValues, _ LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False) If FoundCell Is Nothing Then KeepLooking = False Else Set FirstFound = FoundCell KeepLooking = True End If Do While KeepLooking Ct = Ct + 1 Cell2Find.Offset(, Ct).Hyperlinks.Add Cell2Find.Offset(, Ct), "", FoundCell.Address(external:=True), FoundCell.Address(external:=True) 'Set FoundCell = Nothing Set FoundCell = .UsedRange.FindNext(FoundCell) If FoundCell Is Nothing Then KeepLooking = False If FoundCell.Address = FirstFound.Address Then KeepLooking = False Loop End With End If Next End Sub
I am trying to look for words on a cell that with an specific criteria to search for example, if cells A2 contains AR to check cell B2 for certain words on cell X2, X3, X4,... that match it, the problem that I have about 34 different conditions to analyse it, I have tried with an excel formula but it throws a lot of false positives ( =SUMPRODUCT(--ISNUMBER(SEARCH($X2$:$X34$,B2)))>0 ) because I packed all the certain words on one list. I can't think of a way to isolate my search for all the 34 different conditions in a way to avoid the false positives bear in mind this excel doc has about 15k rows. I wonder if I could adjust my formula to be a bit more specific, I have tried with IF statements but it didn't work either, i wonder if there is a way to create a macro / vba to do it Many thanks