+ Reply to Thread
Results 1 to 25 of 25

search for rows in table that contains all words from a string

  1. #1
    Forum Contributor
    Join Date
    06-05-2013
    Location
    Austria
    MS-Off Ver
    Excel 2016
    Posts
    165

    search for rows in table that contains all words from a string

    Hy everyone,

    after searching and trying a lot with formulas and VBA Examples I had no luck to find a solution for my problem. So I ask you for your help.
    I have the following problem:
    I get a lot of strings with product names and I have to find the matching ID for these strings. The problem is, that these strings to not match with my tables that contains the product names because of a different order of the words in these strings. So I had the following idea:
    A macro "splits" the string into single parts and look in the tables, if a row contains all of these parts. And, when found, show the ID.

    In my workbook I have examples to show my idea.
    I hope you can help me.

    Kind Regards
    Roman
    Attached Files Attached Files

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: search for rows in table that contains all words from a string

    Try this for results in column "C".
    Please Login or Register  to view this content.
    Regards Mick

    http://www.dec.org.uk/

  3. #3
    Forum Contributor
    Join Date
    06-05-2013
    Location
    Austria
    MS-Off Ver
    Excel 2016
    Posts
    165

    Re: search for rows in table that contains all words from a string

    Hy Mick,
    thanks for your code. I have tried it, but nothing happens...! Nothing is found...

  4. #4
    Forum Contributor
    Join Date
    06-05-2013
    Location
    Austria
    MS-Off Ver
    Excel 2016
    Posts
    165

    Re: search for rows in table that contains all words from a string

    I found my mistake!! It works. Thanks a lot.
    When I need more tables, then I have to change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Right?

    Can you please help make make the search case sensitive?

    THANK YOU!!!

  5. #5
    Forum Contributor
    Join Date
    06-05-2013
    Location
    Austria
    MS-Off Ver
    Excel 2016
    Posts
    165

    Re: search for rows in table that contains all words from a string

    One quick question. In cell C4 I can see the result. Very cool. But in cells C9 and C 15 are results too. These cells were just for the examples. How can the code be modified that C2 is the only cell to search and cell C4 is only for the results? Thank YOU

  6. #6
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: search for rows in table that contains all words from a string

    Forget that, Try this modified code:-
    Please Login or Register  to view this content.
    Regards Mick

    http://www.dec.org.uk/
    Last edited by MickG; 04-17-2017 at 01:18 PM.

  7. #7
    Forum Contributor
    Join Date
    06-05-2013
    Location
    Austria
    MS-Off Ver
    Excel 2016
    Posts
    165

    Re: search for rows in table that contains all words from a string

    Hi Mick,
    thanks for your help. After thinking about your code I had a great idea.
    My first idea was to find one position and then the next. But it would be awesome, if I can search for more results in one step.
    So I only have to type in the search text for n positions and then I get the result for each of them.
    For each search there is only one result. Everything in the tables is unique. (I hope so :-) )
    Sorry for take your time with all my questions.

    Kind Regards
    Roman
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    06-05-2013
    Location
    Austria
    MS-Off Ver
    Excel 2016
    Posts
    165

    Re: search for rows in table that contains all words from a string

    I got it!! ( I hope so)

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    06-05-2013
    Location
    Austria
    MS-Off Ver
    Excel 2016
    Posts
    165

    Re: search for rows in table that contains all words from a string

    THANKS A LOT FOR YOUR HELP!
    This is great!!!
    I will try your code with all of my data. If there are troubles, I will ask you again ;-)

    Thanks Mick

    Kind Regards
    Roman

  10. #10
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Another way …


    Hi Roman !

    According to your post #7 attachment try this demonstration :

    PHP Code: 
    Sub Demo()
             
    Dim Rg As RangeRf As RangeSPVW&, A$, N&, R&, C&
        For 
    Each Rg In Tabelle1.UsedRange.Offset(1).Columns(3).SpecialCells(xlCellTypeConstants)
               
    SP Split(Rg.Value)
                
    "Nothing !"
            
    For 2 To ThisWorkbook.Worksheets.Count
                With ThisWorkbook
    .Worksheets(W).UsedRange
                       Set Rf 
    = .Find(SP(0), , xlValuesxlWholexlByRows)
                    If 
    Not Rf Is Nothing Then
                       A 
    Rf.Address
                        
    Do
                                
    0
                                R 
    Rf.Row - .Row 1
                            
    If Application.CountA(.Rows(R)) - UBound(SPThen
                                
    For 1 To UBound(SP)
                                    If .
    Rows(R).Find(SP(C)) Is Nothing Then Exit For
                                    
    1
                                Next
                                 
    If UBound(SPThen V = .Cells(R- (.Column 1)).Value: Exit For
                            
    End If
                               
    Set Rf = .Find(SP(0), Rf)
                        
    Loop Until Rf.Address A
                    End 
    If
                
    End With
            Next
                 Rg
    (12).Value V
        Next
                 Set Rf 
    Nothing
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 04-17-2017 at 08:33 PM. Reason: optimization …

  11. #11
    Forum Contributor
    Join Date
    06-05-2013
    Location
    Austria
    MS-Off Ver
    Excel 2016
    Posts
    165

    Re: search for rows in table that contains all words from a string

    Hi Marc L,
    thanks for your code. Looks very good. I will try all your examples with a big data base. I hope it will work with thousands of cells ;-)

    Kind regards
    Roman

  12. #12
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: search for rows in table that contains all words from a string

    You're welcome

  13. #13
    Forum Contributor
    Join Date
    06-05-2013
    Location
    Austria
    MS-Off Ver
    Excel 2016
    Posts
    165

    Re: search for rows in table that contains all words from a string

    Hi, it´s me again

    with your help I am very happy and it really works great. But I have another question and I hope you can help me.
    The macro from MickG is the one I am using. It founds more results than the macro from Marc L ( I don´t know why).
    I tried to modify the macro that this would work:

    If the row with the matching strings is found, then the value from row x, column B is written in Sheet ("input") column D. Very cool.
    Now I tried with vlookup and VBA to get the values from C:H from the sheet and row where the founded value is from and put it into sheet ("input") column E.
    So I get the "original" name. But there are problems with finding this matching cell and there are a lot of spaces when cells are empty in my tables.

    I hope you can help me again

    Kind Regards
    Roman

  14. #14
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb

    Quote Originally Posted by moosmahna View Post
    The macro from MickG is the one I am using. It founds more results than the macro from Marc L ( I don´t know why).
    As my code works only for exact match of words number !
    Example with "green car", my code does not return 100,27 from Data_01!B4 ('cause of "red green car" …)
    neither 100,30 from B7 (aka "big green House 4 car") but 200,16 from Data_02!B4 as "car green" …

    A new demonstration updating column E :

    PHP Code: 
    Sub Demo2()
             
    Dim Rg As RangeRf As RangeSPVW&, A$, N&, R&, C&
        For 
    Each Rg In Tabelle1.UsedRange.Offset(1).Columns(3).SpecialCells(xlCellTypeConstants)
               
    SP Split(Rg.Value)
                
    = [{"Nothing !",""}]
            For 
    2 To ThisWorkbook.Worksheets.Count
                With ThisWorkbook
    .Worksheets(W).UsedRange
                       Set Rf 
    = .Find(SP(0), , xlValuesxlWholexlByRows)
                    If 
    Not Rf Is Nothing Then
                       A 
    Rf.Address
                        
    Do
                                
    0
                                R 
    Rf.Row - .Row 1
                            
    If Application.CountA(.Rows(R)) - UBound(SPThen
                                
    For 1 To UBound(SP)
                                    If .
    Rows(R).Find(SP(C)) Is Nothing Then Exit For
                                    
    1
                                Next
                                 
    If UBound(SPThen
                                    V 
    = Array(.Cells(R- (.Column 1)).Value_
                                              Application
    .Trim(Join(Application.Index(.Rows(R).Offset(, 1).Value, , 0))))
                                    Exit For
                                 
    End If
                            
    End If
                               
    Set Rf = .Find(SP(0), Rf)
                        
    Loop Until Rf.Address A
                    End 
    If
                
    End With
            Next
                 Rg
    (12).Resize(, 2).Value V
        Next
                 Set Rf 
    Nothing
    End Sub 
    You may like it !
    Last edited by Marc L; 04-19-2017 at 05:24 AM. Reason: typo …

  15. #15
    Forum Contributor
    Join Date
    06-05-2013
    Location
    Austria
    MS-Off Ver
    Excel 2016
    Posts
    165

    Re: search for rows in table that contains all words from a string

    Hi Marc L
    thanks for your answer. Your macro shows a lot of errors in the cells in column E and D.
    I need a macro (MickG) that searches if the words are in a row in a table. Because the strings I get are not always in the order I want to.
    e.g. I would need: this green car
    and I get green car this

    Kind Regards
    Roman

  16. #16
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question

    [duplicate to remove]

  17. #17
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: search for rows in table that contains all words from a string


    My code seems to well work on my side with your post #7 attachment !

    At least give some examples upon this attachment …

  18. #18
    Forum Contributor
    Join Date
    06-05-2013
    Location
    Austria
    MS-Off Ver
    Excel 2016
    Posts
    165

    Re: search for rows in table that contains all words from a string

    Hy Marc L,
    I have tested it and it looks good. It finds the right results. I don´t know what happened before.
    I have 2 more questions. I wrote them into the workbook, because it is a little bit difficult to explain without a workbook.
    And because of my english :-)

    Many Thanks
    Kind Regards

    Roman
    Attached Files Attached Files

  19. #19
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: search for rows in table that contains all words from a string


    Delete Demo2 procedure in modul3 and paste post #14 code …

  20. #20
    Forum Contributor
    Join Date
    06-05-2013
    Location
    Austria
    MS-Off Ver
    Excel 2016
    Posts
    165

    Re: search for rows in table that contains all words from a string

    Thanks, the error is gone. Cool

    Can you please help me with the ideas I have written in the workbooK?

    Thanks

  21. #21
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Try this !


    PHP Code: 
    Sub Demo3()
             
    Dim Rg As RangeRf As RangeSPVU%, W&, A$, N&, R&, C&
        For 
    Each Rg In Tabelle1.UsedRange.Offset(1).Columns(3).SpecialCells(xlCellTypeConstants)
               
    SP Split(Rg.Value)
                
    = [{"Nothing !",""}]
                
    0
          
    Do
            For 
    2 To ThisWorkbook.Worksheets.Count
                With ThisWorkbook
    .Worksheets(W).UsedRange
                       Set Rf 
    = .Find(SP(0), , xlValuesxlWholexlByRows)
                    If 
    Not Rf Is Nothing Then
                       A 
    Rf.Address
                        
    Do
                                
    0
                                R 
    Rf.Row - .Row 1
                            
    If Application.CountA(.Rows(R)) - UBound(SPThen
                                
    For 1 To UBound(SP)
                                    If .
    Rows(R).Find(SP(C)) Is Nothing Then Exit For
                                    
    1
                                Next
                                 
    If UBound(SPThen
                                    V 
    = Array(.Cells(R- (.Column 1)).Value_
                                              Application
    .Trim(Join(Application.Index(.Rows(R).Offset(, 1).Value, , 0))))
                                    Exit For
                                 
    End If
                            
    End If
                               
    Set Rf = .Find(SP(0), Rf)
                        
    Loop Until Rf.Address A
                    End 
    If
                
    End With
            Next
                
    If LBound(V) = Or (UBound(SP) < And 0) Or UBound(SP) + 1 Then Exit Do
                
    SP Split(Rg.Value)
                
    SP Filter(SPSP(U), False):   If UBound(SP) < 0 Then Exit Do
                 
    1
          Loop
                Rg
    (12).Resize(, 2).Value V
        Next
                Set Rf 
    Nothing
    End Sub 
    You should - click - like it ‼

    Later when I'll have time I'll think for a better combinations that your incomplete way …

  22. #22
    Forum Contributor
    Join Date
    06-05-2013
    Location
    Austria
    MS-Off Ver
    Excel 2016
    Posts
    165

    Re: search for rows in table that contains all words from a string

    Hy Marc L,
    wow, that looks realy great! I am very happy that you help me. If you have another ideas, it would be awesome!
    Thanks a lot!

    Kind regards
    Roman

  23. #23
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb Try this ‼


    PHP Code: 
    Sub Demo4()
             
    Dim Rc As RangeRg As RangeSPVW&, N&, S
        With Application
            
    .ScreenUpdating False
        
    For Each Rc In Tabelle1.UsedRange.Offset(1).Columns(3).SpecialCells(xlCellTypeConstants)
               
    SP Split(Rc.Value)
                
    = Array("Nothing !""", -1)
            For 
    2 To ThisWorkbook.Worksheets.Count
                
    For Each Rg In ThisWorkbook.Worksheets(W).UsedRange.Rows
                        N 
    = -1
                    
    For Each S In SP
                        
    If Not Rg.Find(S, , xlValuesxlWholeIs Nothing Then N 1
                    Next
                    
    If UBound(SP) And .CountA(Rg) - UBound(SPThen
                       V 
    = Array(Rg.Cells(1).Value, .Trim(Join(.Index(Rg.Offset(, 1).Value, , 0))))
                       Exit For
                    ElseIf 
    V(2Then
                       V 
    = Array(Rg.Cells(1).Value, .Trim(Join(.Index(Rg.Offset(, 1).Value, , 0))), N)
                    
    End If
                
    Next
                    
    If UBound(V) = 1 Then Exit For
            
    Next
                 Rc
    (12).Resize(, 2).Value V
        Next
                     Set Rg 
    Nothing
            
    .ScreenUpdating True
        End With
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 04-19-2017 at 08:19 PM. Reason: optimization …

  24. #24
    Forum Contributor
    Join Date
    06-05-2013
    Location
    Austria
    MS-Off Ver
    Excel 2016
    Posts
    165

    Re: search for rows in table that contains all words from a string

    Thanks!!! I will test it tomorrow. Today I have a lot of work. I will tell you how it works!
    Kind Regards
    Roman

  25. #25
    Forum Contributor
    Join Date
    06-05-2013
    Location
    Austria
    MS-Off Ver
    Excel 2016
    Posts
    165

    Re: search for rows in table that contains all words from a string

    Hy, it´s me again :-)

    I tested it in the last days and it works good. But there is one thing I cannot handle.
    I need help when I want to search manually besauce it is possible that there are some articles with the same name and attributes on different sheets.
    In my workbook I have an example how it should work.

    THANKS AGAIN

    Kind regards
    Roman
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Search for string within a table and all rows that contain the string
    By shoulddt in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-31-2016, 12:27 PM
  2. Search string for words in dictionary
    By sdl2 in forum Excel General
    Replies: 4
    Last Post: 03-15-2015, 05:40 PM
  3. Replies: 15
    Last Post: 10-12-2014, 08:53 AM
  4. Word macro help.. search words in string with no spaces...
    By danielronnstam in forum Word Programming / VBA / Macros
    Replies: 1
    Last Post: 02-23-2014, 11:35 AM
  5. Search string of words in text
    By excelnik in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 05-31-2013, 05:10 PM
  6. search for multiple words in a string
    By pcbpinoy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-28-2011, 04:03 AM
  7. [SOLVED] How do I do a multiple search using key words in a text string
    By patricia tipp in forum Excel General
    Replies: 1
    Last Post: 02-28-2006, 01:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1