SOLVED

Formula does not work for all

%3CLINGO-SUB%20id%3D%22lingo-sub-197694%22%20slang%3D%22en-US%22%3EFormula%20does%20not%20work%20for%20all%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-197694%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20using%26nbsp%3B%3DIF(ISNUMBER(SEARCH(%22RangeName%22%2CG2))%2CRangeName)%20to%20find%20words%20in%20a%20cell%20for%20list%20of%20words.%20Once%20that%20word%20is%20found%20I%20want%20that%20word%20to%20be%20the%20result%20if%20the%20words%20nor%20found%20than%20say%20FALSE.%20I%20used%20this%20formula%20in%207%2C000%20cells%20only%201%20cell%20came%20back%20with%20correct%20answer.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhy%20is%20that%3F%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-197694%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20%26amp%3B%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ENeed%20Help%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-197791%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20does%20not%20work%20for%20all%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-197791%22%20slang%3D%22en-US%22%3E%3CP%3EThank%20you%20so%20much%20Matt.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20worked.%26nbsp%3B%3C%2FP%3E%3CP%3EThanks.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-197779%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20does%20not%20work%20for%20all%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-197779%22%20slang%3D%22en-US%22%3E%3CP%3ETry%20using%20the%20below%20VBA%20Code%20to%20get%20the%20result%20you%20would%20like.%26nbsp%3B%20I'm%20attaching%20a%20.xlsx%20workbook%20as%20an%20example%20since%20it's%20not%20possible%20to%20attach%20macro%20enabled%20workbooks.%26nbsp%3B%20You%20will%20need%20to%20insert%20the%20code%20I%20have%20provided%20below%20into%20the%20workbook%20to%20see%20how%20it%20works.%26nbsp%3B%20Once%20you%20grasp%20the%20concept%20you%20can%20alter%20the%20code%20to%20work%20for%20your%20needs.%26nbsp%3B%20Hope%20this%20helps.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBefore%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20939px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F34892i8A6A85884666B83B%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22SentimentBefore.png%22%20title%3D%22SentimentBefore.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAfter%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20842px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F34893i499B60F8A909FACD%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22SentimentAfter.png%22%20title%3D%22SentimentAfter.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECode%3A%3C%2FP%3E%0A%3CPRE%3ESub%20GetWords()%0A%0A%20%20%20%20Dim%20wrdLRow%20As%20Integer%0A%20%20%20%20Dim%20wrdLp%20As%20Integer%0A%20%20%20%20Dim%20CommentLrow%20As%20Integer%0A%20%20%20%20Dim%20CommentLp%20As%20Integer%0A%20%20%20%20Dim%20fndWord%20As%20Integer%0A%20%20%20%20Dim%20Sht%20As%20Worksheet%0A%20%20%20%20%0A%20%20%20%20On%20Error%20Resume%20Next%20'Suppress%20Errors...%20for%20when%20we%20don't%20find%20a%20match%0A%20%20%20%20%0A%20%20%20%20'Define%20worksheet%20that%20has%20data%20on%20it....%0A%20%20%20%20Set%20Sht%20%3D%20Sheets(%22Sheet1%22)%0A%20%20%20%20%0A%20%20%20%20'Get%20last%20row%20for%20words%20based%20on%20column%20A%0A%20%20%20%20wrdLRow%20%3D%20Sht.Cells(Rows.Count%2C%20%22A%22).End(xlUp).Row%0A%20%20%20%20%0A%20%20%20%20'Get%20last%20row%20for%20comments%20based%20on%20column%20C%0A%20%20%20%20CommentLrow%20%3D%20Sht.Cells(Rows.Count%2C%20%22C%22).End(xlUp).Row%0A%20%20%20%20%0A%20%20%20%20'Loop%20through%20lists%20and%20find%20matches....%0A%20%20%20%20For%20CommentLp%20%3D%202%20To%20CommentLrow%0A%20%20%20%20%0A%20%20%20%20%20%20%20%20For%20wrdLp%20%3D%202%20To%20wrdLRow%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20'Look%20for%20word...%0A%20%20%20%20%20%20%20%20%20%20%20%20fndWord%20%3D%20Application.WorksheetFunction.Search(Sht.Cells(wrdLp%2C%20%22A%22)%2C%20Sht.Cells(CommentLp%2C%20%22C%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20'If%20we%20found%20the%20word....then%0A%20%20%20%20%20%20%20%20%20%20%20%20If%20fndWord%20%26gt%3B%200%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Sht.Cells(CommentLp%2C%20%22D%22)%20%3D%20Sht.Cells(CommentLp%2C%20%22D%22)%20%26amp%3B%20%22%3B%20%22%20%26amp%3B%20Sht.Cells(wrdLp%2C%20%22A%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20fndWord%20%3D%200%20'Reset%20Variable%20for%20next%20loop%0A%20%20%20%20%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20Next%20wrdLp%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20Sht.Cells(CommentLp%2C%20%22D%22)%20%3D%20Mid(Sht.Cells(CommentLp%2C%20%22D%22)%2C%203%2C%20Len(Sht.Cells(CommentLp%2C%20%22D%22))%20-%202)%0A%0A%20%20%20%20Next%20CommentLp%0A%0AEnd%20Sub%0A%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-197732%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20does%20not%20work%20for%20all%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-197732%22%20slang%3D%22en-US%22%3E%3CP%3EThank%20you%20Matt%20for%20your%20reply.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUnfortunately%20I%20am%20unable%20to%20share%20any%20data%20with%20you.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20doing%20a%20sentimental%20analysis%20and%20trying%20to%20pick%20up%20positive%20or%20negative%20words%20and%20than%20score%20each%20words.%20I%20am%20unable%20to%20find%20a%20solution%20that%20will%20help%20me%20do%20this%20in%20excel.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-197730%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20does%20not%20work%20for%20all%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-197730%22%20slang%3D%22en-US%22%3E%3CP%3EWould%20a%20VBA%20Code%20solution%20be%20acceptable%3F%26nbsp%3B%20I%20can't%20think%20of%20an%20easy%20way%20to%20do%20this%20otherwise.%26nbsp%3B%20If%20this%20is%20acceptable%20then%20would%20it%20be%20possible%20for%20you%20to%20give%20me%20a%20small%20set%20of%20non-sensitive%20data%20that%20I%20can%20test%20the%20code%20on%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETypically%2C%20my%20coworkers%20use%20text%20analytics%2F%20sentiment%20analysis%20packages%20for%20statistical%20software%20to%20do%20things%20of%20this%20nature.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-197711%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20does%20not%20work%20for%20all%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-197711%22%20slang%3D%22en-US%22%3E%3CP%3EThank%20you%20Matt%20for%20the%20quick%20response.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20list%20of%202000%20words%20that%20I%20am%20looking%20for%20in%20the%207000%20cell%20that%20contains%20comments.%20(min%2020%20word%20count%20per%20cell).%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20i%20use%20the%26nbsp%3B%3DIF(OR(ISNUMBER(SEARCH(%22nice%22%2CA10))%2CISNUMBER(SEARCH(%22great%22%2CA10))%2CISNUMBER(SEARCH(%22thank%22%2CA10)))%2C%22yes%22%2C%22no%22)%20this%20works%20perfectly%20but%20only%20for%20selected%20words.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20I%20want%20is%20a%20formula%20that%20will%20read%20comments%20in%207000%20cells%20and%20look%20for%20any%20of%20the%202000%20word%20list%20that%20I%20have.%20Once%20it%20finds%20that%20word%20I%20wanted%20it%20to%20tell%20me%20each%20words%20it%20found%20in%20each%20comments.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-197704%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20does%20not%20work%20for%20all%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-197704%22%20slang%3D%22en-US%22%3E%3CP%3ETry%20using%20a%20formula%20like%20the%20below.%26nbsp%3B%20I%20have%20attached%20an%20example%20file%20for%20additional%20reference%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3DIF(ISERROR(SEARCH(%24C%242%2CF2))%2C%22FALSE%22%2C%24C%242)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20931px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F34878i0F48056F136B189C%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22SearhEx.png%22%20title%3D%22SearhEx.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2354696%22%20slang%3D%22en-US%22%3ERe%3A%20Formula%20works%20well%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2354696%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F37127%22%20target%3D%22_blank%22%3E%40Matt%20Mickle%3C%2FA%3E%26nbsp%3BIs%20it%20possible%20to%20extract%20the%20whole%20sentence%20containing%20word%20listed%20in%20column%20A%20rather%20than%20just%20a%20word.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

I am using =IF(ISNUMBER(SEARCH("RangeName",G2)),RangeName) to find words in a cell for list of words. Once that word is found I want that word to be the result if the words nor found than say FALSE. I used this formula in 7,000 cells only 1 cell came back with correct answer. 

 

Why is that? 

7 Replies

Try using a formula like the below.  I have attached an example file for additional reference:

 

=IF(ISERROR(SEARCH($C$2,F2)),"FALSE",$C$2)

 

SearhEx.png

Thank you Matt for the quick response. 

 

I have list of 2000 words that I am looking for in the 7000 cell that contains comments. (min 20 word count per cell). 

 

If i use the =IF(OR(ISNUMBER(SEARCH("nice",A10)),ISNUMBER(SEARCH("great",A10)),ISNUMBER(SEARCH("thank",A10))),"yes","no") this works perfectly but only for selected words. 

 

What I want is a formula that will read comments in 7000 cells and look for any of the 2000 word list that I have. Once it finds that word I wanted it to tell me each words it found in each comments. 

 

Thanks 

Would a VBA Code solution be acceptable?  I can't think of an easy way to do this otherwise.  If this is acceptable then would it be possible for you to give me a small set of non-sensitive data that I can test the code on?

 

Typically, my coworkers use text analytics/ sentiment analysis packages for statistical software to do things of this nature.

Thank you Matt for your reply. 

 

Unfortunately I am unable to share any data with you. 

 

I am doing a sentimental analysis and trying to pick up positive or negative words and than score each words. I am unable to find a solution that will help me do this in excel.  

 

Thanks 

best response confirmed by Nruti Desai (New Contributor)
Solution

Try using the below VBA Code to get the result you would like.  I'm attaching a .xlsx workbook as an example since it's not possible to attach macro enabled workbooks.  You will need to insert the code I have provided below into the workbook to see how it works.  Once you grasp the concept you can alter the code to work for your needs.  Hope this helps.

 

Before:

SentimentBefore.png

 

After:

SentimentAfter.png

 

Code:

Sub GetWords()

    Dim wrdLRow As Integer
    Dim wrdLp As Integer
    Dim CommentLrow As Integer
    Dim CommentLp As Integer
    Dim fndWord As Integer
    Dim Sht As Worksheet
    
    On Error Resume Next 'Suppress Errors... for when we don't find a match
    
    'Define worksheet that has data on it....
    Set Sht = Sheets("Sheet1")
    
    'Get last row for words based on column A
    wrdLRow = Sht.Cells(Rows.Count, "A").End(xlUp).Row
    
    'Get last row for comments based on column C
    CommentLrow = Sht.Cells(Rows.Count, "C").End(xlUp).Row
    
    'Loop through lists and find matches....
    For CommentLp = 2 To CommentLrow
    
        For wrdLp = 2 To wrdLRow

            'Look for word...
            fndWord = Application.WorksheetFunction.Search(Sht.Cells(wrdLp, "A"), Sht.Cells(CommentLp, "C"))
            
            'If we found the word....then
            If fndWord > 0 Then
                Sht.Cells(CommentLp, "D") = Sht.Cells(CommentLp, "D") & "; " & Sht.Cells(wrdLp, "A")
                fndWord = 0 'Reset Variable for next loop
            End If
            
        Next wrdLp
        
        Sht.Cells(CommentLp, "D") = Mid(Sht.Cells(CommentLp, "D"), 3, Len(Sht.Cells(CommentLp, "D")) - 2)

    Next CommentLp

End Sub

 

 

Thank you so much Matt.

 

It worked. 

Thanks.

@Matt Mickle Is it possible to extract the whole sentence containing word listed in column A rather than just a word.