+ Reply to Thread
Results 1 to 45 of 45

Search and extract all the possible letters

  1. #1
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Search and extract all the possible letters

    Hi excel experts

    In sheet1 column A, there are a lot of words of search for
    In cell C1 I would type some letters to search for in these list in column A

    If I type in cell C1 the letters "ACT" then I need to list all the words that contains these letters so the results would be [ACT - CAT - AT - ...]
    The rule is to make sure the word has all the letters in "ACT"

    If I typed in cell C1 the letters "ACT?". The question mark means any other character so the results should be as the following [ACT - CAT - AT - ACTS - CAST - ATOC ... and so on]
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,192

    Re: Search and extract all the possible letters

    Please Login or Register  to view this content.
    Attached Files Attached Files
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    Amazing. Thank you so much
    One remark when typing "ACT" I got an extra letter in results such as "ACTS" why?
    When not using the question mark then I don't need to get extra letters so "ACTS", "ATOC" ... are not acceptable results. These words are acceptable when using the question mark only

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Search and extract all the possible letters

    1) Sheet1 code module
    Please Login or Register  to view this content.
    to a satandrd code module
    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,192

    Re: Search and extract all the possible letters

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by JohnTopley; 08-04-2022 at 02:06 AM.

  6. #6
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    Charm. Thank you so much all of you
    You are so helpful.

  7. #7
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    @jindon
    Can you add a remark to the solution?

    Type two words in column A. eg "AT" and "CA"
    then in cell c1 type "ACT?" and run your macro
    These two words "AT" and "CA" are not included. Is it probable to include them too in the results?

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Search and extract all the possible letters

    Now I don't understand the logic.

    Upload a workbook with sll the possible data in col.A and the result that you want for few examples of C1.

    i.e
    result when C1 = AT, result when C1 = bla bla, so that I can see what you really want to do.

  9. #9
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    I have put two examples of searching letters and the results (but I wanted the results to be in a column as you did before)
    Attached Files Attached Files

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Search and extract all the possible letters

    Change to
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    You are incredibly genius man. Thank you so much.

  12. #12
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    I am so so sorry. Try typing the word "ZOOT" in column A and type "ACT?" in cell A1
    When running the code, this word comes with results!!!
    The question mark means only one unknown character so "ZOOT" is incorrect in that case as it has the letter "T" and that is OK but also has "O" & "O" & "Z" (and only one unknown character is acceptable)

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Search and extract all the possible letters

    Explain the logic in understandable form

    You said
    AT? >>> AT TA AG TO MAT RAT ACT ZA TI TEA

    But
    ACT? >>> should exclude ZOOT

    Why?

  14. #14
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    In "AG" the letter "A" is in the searched letters and the letter "G" for the question mark
    In "TO" the letter "T" is in the searched letters and the letter "O" for the question mark
    In "ZA" the letter "A" is in the searched letters and the letter "Z" for the question mark
    In "TI" the letter "T" is in the searched letters and the letter "I" for the question mark

  15. #15
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,779

    Re: Search and extract all the possible letters

    This thread is marked as solved, and clearly is not.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  16. #16
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Search and extract all the possible letters

    You are not answering to my question.

    If "?" at the end is a wild card, I understnad for 2 characters.
    matches to col.A contains both charcters, or one of two with one other character.

    If 3 characres with ?, what?

  17. #17
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    No, I mean the question mark is only for one missing character not more than a character.
    I usually use only one question mark or two at most

  18. #18
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Search and extract all the possible letters

    So, what is the logic for the characters more than 2?

    I'll be busy rest of the day.
    Just my guess, if it is not what you want, upload a workbook that is telling everything clearly.
    Please Login or Register  to view this content.
    Last edited by jindon; 08-05-2022 at 08:57 PM.

  19. #19
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    Amazing sir Jindon. I tested each possibility and the last code was perfect.
    Thank you so much.

  20. #20
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    one remark as for the last working and perfect code
    If I put a word "ANTA" and typed the letters in c1 "ACT?", all the results are well and acceptable except the word "ANTA". This word is not acceptable in that case
    the letter "A" is ok and the letter "T" is ok
    the question mark is for either the letter "A" or "N" not both of them
    I mean that the letter in the searched letters is used for just once not twice so if the letter "A" is typed in the searched letters once, so it would be used once. If typed twice, it would be used twice

    e.g
    if there is a word "COCA" in column A and I typed "ACC?" so "COCA" is acceptable as the letter "C" twice in the searched letters and "A" is already there and the letter "O" is for the question mark

  21. #21
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Search and extract all the possible letters

    Not clear at all.

    You must mention the rule(s) when entering to C1.

    Is something like "AACT?" happen in C1???

    I said you must upload the possible variation of data and the results that you want clearly explaining everything...

    This will be endless...

  22. #22
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,463

    Re: Search and extract all the possible letters

    This code trigger any change in column A or cell C1.
    Righ click on tab's name, view code then paste below code into editting window:
    Maybe, try:
    PHP Code: 
    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim lr&, i&, j&, m&, c&, k&, rngScell As StringLcell As StringAs Stringarr(1 To 100001 To 1)
    If 
    Not Intersect(TargetUnion(Columns(1), Range("C1"))) Is Nothing Then
    lr 
    Cells(Rows.Count"A").End(xlUp).Row
    rng 
    Range("A1:A" lr).Value
    Scell 
    Range("C1").Value ' search cell
    For i = 1 To lr
        Lcell = rng(i, 1) ' 
    Looking range
        c 
    Len(Lcell) - IIf(InStr(1Scell"?"), 10)
        If 
    Len(Lcell) <= Len(ScellThen
            
    For 1 To Len(Lcell)
                For 
    1 To Len(Scell)
                    If 
    Mid(Lcellj1) = Mid(IIf(""Scells), m1Then
                        c 
    1
                        s 
    Replace(IIf(""Scells), Mid(Lcellj1), ""11)
                    
    End If
                
    Next
            Next
            
    If 1 Then
                k 
    1
                arr
    (k1) = Lcell
            End 
    If
        
    End If
        
    ""
    Next
    Range
    ("B2:B10000").ClearContents
    If 0 Then Range("B2").Resize(k1).Value arr
    End 
    If
    End Sub 
    Quang PT

  23. #23
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    Thank you so much sir jindon and sir bebo
    The last code of bebo was perfect in all the cases I tested till now.
    Awesome help from awesome experts

  24. #24
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    @bebo
    The code is really amazing. Can you add something if possible?
    If the searched letters have the question mark then I need to add between brackets the letter that substituted the question mark
    e.g.
    the searched letters "AACT?" and in results the word "ANTA". I need the result to be like that
    Please Login or Register  to view this content.

  25. #25
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    In column A type the word "RHOTIC" and in c1 type these letters "ETIRCOR" (without the question mark)
    You will notice the word comes with results although it has no "H" letter !!?

  26. #26
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    The question in simple words
    check each word letters opposite the searched letters and make sure all the letters are already there
    the words "ACTS" & "CATS" is acceptable if the searched letters was "ACT?"

  27. #27
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,463

    Re: Search and extract all the possible letters

    Soory for late reply.
    try again.
    PHP Code: 
    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim lr&, i&, j&, m&, c&, k&, rngScell As StringLcellex As Stringarr(1 To 100001 To 1)
    Dim dic As Objectkey
    If Not Intersect(TargetUnion(Columns(1), Range("C1"))) Is Nothing Then
        lr 
    Cells(Rows.Count"A").End(xlUp).Row
        rng 
    Range("A1:B" lr).Value
        Scell 
    Range("C1").Value ' search cell
        For i = 1 To lr
            Set dic = CreateObject("Scripting.Dictionary")
            For j = 1 To Len(Scell)
                If Not dic.exists(Mid(Scell, j, 1)) Then
                    dic.Add Mid(Scell, j, 1), 1
                Else
                    dic(Mid(Scell, j, 1)) = dic(Mid(Scell, j, 1)) + 1
                End If
            Next
            Lcell = rng(i, 1) ' 
    Looking range
            
    If Len(Lcell) <= Len(ScellThen
                ex 
    ""
                
    For 1 To Len(Lcell)
                    
    0
                    
    For Each key In dic.keys
                        
    If Mid(Lcellj1) = key Then
                            c 
    1
                            Select 
    Case dic(key)
                                Case 
    Is 0
                                    dic
    (key) = dic(key) - 1
                                
    Case Else
                                    
    ex ex Mid(Lcellj1)
                            
    End Select
                        End 
    If
                    
    Next
                    
    If 0 Then ex ex Mid(Lcellj1)
                
    Next
                
    If ex "" Or (Len(ex) = And Right(Scell1) = "?"Then
                    k 
    1
                    arr
    (k1) = Lcell IIf(ex """"" [" ex "]")
                
    End If
            
    End If
            
    Set dic Nothing
        Next
        Range
    ("B2:B10000").ClearContents
        
    If 0 Then Range("B2").Resize(k1).Value arr
    End 
    If
    End Sub 
    Attached Files Attached Files

  28. #28
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    Saying thank you is not enough for both of you
    The last code solved all the possibilities I was facing
    Thank you so much

  29. #29
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    When trying the code with words 80,000 in column A, it takes a too long time. Is it possible to deal with such a number of words?

  30. #30
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,463

    Re: Search and extract all the possible letters

    With 80,000 rows, a dictionary is created then removed ... x 80000 times
    Definietly its not a proper choice.
    Does it annoy too much, if I employed few rows-columns in the right as helper columns (for ex, range E1:P3), to avoid dictionary life cycle loop? They can be deleted after run. And make sure they are availlable.

  31. #31
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    No problem at all after column "W". Thank you so much for you are patient with me.

  32. #32
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,463

    Re: Search and extract all the possible letters

    Try again. Not use any helpers at all.
    PHP Code: 
    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim lr&, i&, j&, m&, c&, k&, n&, rngScell As StringLcellex As Stringarr(1 To 100001 To 1), arr1sArr(1 To 1001 To 2)
    Dim dic As Objectkey
    If Not Intersect(TargetUnion(Columns(1), Range("C1"))) Is Nothing Then
        lr 
    Cells(Rows.Count"A").End(xlUp).Row
        rng 
    Range("A1:B" lr).Value
        Scell 
    Range("C1").Value ' search cell
        Set dic = CreateObject("Scripting.Dictionary")
        For j = 1 To Len(Scell)
            If Not dic.exists(Mid(Scell, j, 1)) Then
                dic.Add Mid(Scell, j, 1), 1
                k = k + 1: sArr(k, 1) = Mid(Scell, j, 1): sArr(k, 2) = 1
            Else
                dic(Mid(Scell, j, 1)) = dic(Mid(Scell, j, 1)) + 1
                For i = 1 To k
                    If sArr(k, 1) = Mid(Scell, j, 1) Then sArr(k, 2) = dic(Mid(Scell, j, 1))
                Next
            End If
        Next
        For i = 1 To lr
            arr1 = sArr
            Lcell = rng(i, 1) ' 
    Looking range
            
    If Len(Lcell) <= Len(Scell) And Lcell <> "" Then
                ex 
    ""
                
    For 1 To Len(Lcell)
                    
    0
                    
    For 1 To k
                        
    If Mid(Lcellj1) = arr1(m1Then
                            c 
    1
                            Select 
    Case arr1(m2)
                                Case 
    Is 0
                                    arr1
    (m2) = arr1(m2) - 1
                                
    Case Else
                                    
    ex ex Mid(Lcellj1)
                            
    End Select
                        End 
    If
                    
    Next
                    
    If 0 Then ex ex Mid(Lcellj1)
                
    Next
                
    If ex "" Or (Len(ex) = And Right(Scell1) = "?"Then
                    n 
    1
                    arr
    (n1) = Lcell IIf(ex """"" [" ex "]")
                
    End If
            
    End If
        
    Next
        Range
    ("B2:B10000").ClearContents
        
    If 0 Then Range("B2").Resize(n1).Value arr
    End 
    If
    End Sub 

  33. #33
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    Thanks a million but thanks a billion and more more
    You are brilliant.

    Is it possible to deal with another question mark or this will complicate the code?
    Last edited by KingTamo; 08-10-2022 at 04:14 AM.

  34. #34
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,463

    Re: Search and extract all the possible letters

    Quote Originally Posted by KingTamo View Post
    Is it possible to deal with another question mark or this will complicate the code?
    You are welcome. Feel free to ask more. I have learnt a lot by teaching myself from this project.

  35. #35
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    Thanks a lot
    Is it possible to deal with another question mark or this will complicate the code?

  36. #36
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Search and extract all the possible letters

    i didn't follow the whole topic, just the speed-remark triggered me. How about this one ?
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

  37. #37
    Valued Forum Contributor
    Join Date
    05-03-2022
    Location
    Halifax,Canada
    MS-Off Ver
    365
    Posts
    326

    Re: Search and extract all the possible letters

    In this solution i'm just creating a 2nd column of the values in ColA.
    I then just do a find and replace on each letter e.g. "A","C","T". ... replacing with ""
    Then go back to each cell in copied column to see how much of a string is left. If 1 letter or less then the word in column A meets the criteria.
    In other words I'm not parsing each word in each cell... just parsing the word in C1

    Please Login or Register  to view this content.
    Last edited by nimrod1313; 08-10-2022 at 11:45 AM.

  38. #38
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,463

    Re: Search and extract all the possible letters

    Quote Originally Posted by KingTamo View Post
    Is it possible to deal with another question mark or this will complicate the code?
    Sorry I dont understand what you mean.

  39. #39
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    Quote Originally Posted by bebo021999 View Post
    Sorry I dont understand what you mean.
    I mean to use two question marks instead of one to express two unknow letters. So e.g if I typed "AC??" the word "ACTS" & "CATS" come to the results

  40. #40
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    @bslav amazing code. It is possible to deal with another question mark?

  41. #41
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,463

    Re: Search and extract all the possible letters

    Quote Originally Posted by KingTamo View Post
    if I typed "AC??" the word "ACTS" & "CATS" come to the results
    So, do you still need to add "[]"?

    ACTS[TS]
    CATS[TS]

    ??

  42. #42
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,463

    Re: Search and extract all the possible letters

    So, what possible maximum "?" could be?

  43. #43
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Search and extract all the possible letters

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by bsalv; 08-11-2022 at 02:01 AM.

  44. #44
    Forum Contributor
    Join Date
    11-24-2016
    Location
    Libya
    MS-Off Ver
    Office 365
    Posts
    526

    Re: Search and extract all the possible letters

    Amazing. Thank you so much.
    You are really awesome persons

  45. #45
    Forum Expert
    Join Date
    01-25-2011
    Location
    Belgium, Alveringem
    MS-Off Ver
    Excel 2003, 2007, 365
    Posts
    1,418

    Re: Search and extract all the possible letters

    slightly modified
    Please Login or Register  to view this content.

+ 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. Extract the letters after a word
    By cmb80 in forum Excel General
    Replies: 10
    Last Post: 08-12-2015, 10:05 AM
  2. [SOLVED] I need to extract first 4 letters from a cell
    By cara164 in forum Excel General
    Replies: 4
    Last Post: 11-17-2014, 02:23 PM
  3. [SOLVED] Extract first or first two letters from postcode
    By gilgil2 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 06-09-2014, 03:13 PM
  4. [SOLVED] Search CELL-A for one or two letters and display the found letters in CELL-B
    By adamtre in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-03-2014, 02:43 AM
  5. Need to extract only numbers after certain letters
    By Chippi in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 03-18-2014, 02:34 PM
  6. Replies: 5
    Last Post: 12-30-2012, 10:59 AM
  7. [SOLVED] Extract letters before first number
    By j.lancaster1 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-21-2012, 08:49 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