+ Reply to Thread
Results 1 to 5 of 5

Fuzzy about fuzzy formula code

Hybrid View

  1. #1
    Registered User
    Join Date
    07-07-2010
    Location
    Montana, USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Question Fuzzy about fuzzy formula code

    hello again, so I have another question that needs answerd

    So I have a program already created that searches a specific column in data base, and then the user types in a variable name and the program selects all the rows that have that data in it. I was wondering how (and if possible) I can make it so that when you type in (for example: WD-40, WD 40 and WD40) that the program will still find the appropriate data.

    I looked up something called fuzzy text that might work but I don’t understand how to get it into my current code and make it work.

    I will insert a mini version of my program along with the code so you can see what mean. And note that the “large program” has over 2500 products, and 26 columns. So adding a little bit of extra code really doesn’t bother me. That and this program is used by miners who have their work gloves on so misspelled words, or similar spelled words tend to happen a lot.

    Thanks in advance.

    Private Sub CommandButton1_Click()
     'SEARCH
      Dim Cnt As Long
     Dim Col As Variant
     Dim FirstAddx As String
     Dim FoundMatch As Range
     Dim LastRow As Long
     Dim R As Long
     Dim StartRow As Long
     Dim Wks As Worksheet
          StartRow = 2
         Set Wks = Sheets(1)
                Col = ComboBox1.ListIndex + 1
             If Col = 0 Then
                MsgBox "Please choose a category."
                Exit Sub
             End If
                   If TextBox1.Text = "" Then
              MsgBox "Please enter a search term."
              TextBox1.SetFocus
              Exit Sub
           End If
           
             LastRow = Wks.Cells(Rows.Count, Col).End(xlUp).Row
             LastRow = IIf(LastRow < StartRow, StartRow, LastRow)
                      Set Rng = Wks.Range(Wks.Cells(2, Col), Wks.Cells(LastRow, Col))
                        Set FoundMatch = Rng.Find(What:=TextBox1.Text, _
                                         After:=Rng.Cells(1, 1), _
                                         LookAt:=xlWhole, _
                                         LookIn:=xlValues, _
                                         SearchOrder:=xlByRows, _
                                         SearchDirection:=xlNext, _
                                         MatchCase:=False)
                                         
    
    
              
              If Not FoundMatch Is Nothing Then
                 FirstAddx = FoundMatch.Address
                 ListView1.ListItems.Clear
                              Do
                   Cnt = Cnt + 1
                   R = FoundMatch.Row
                   ListView1.ListItems.Add Index:=Cnt, Text:=R
                     For Col = 1 To 13
                       Set C = Wks.Cells(R, Col)
                       ListView1.ListItems(Cnt).ListSubItems.Add Index:=Col, Text:=C.Text
                    Next Col
                   Set FoundMatch = Rng.FindNext(FoundMatch)
                 Loop While FoundMatch.Address <> FirstAddx And Not FoundMatch Is Nothing
                 SearchRecords = Cnt
              Else
                 ListView1.ListItems.Clear
                 SearchRecords = 0
                 MsgBox "No match found for " & TextBox1.Text
              End If
              End Sub
    
    
    Private Sub UserForm_Activate()
    
      Dim C As Long
      Dim i As Long
      Dim R As Long
      Dim Wks As Worksheet
              ListView1.View = lvwReport
        ListView1.HideSelection = False
        ListView1.FullRowSelect = True
        ListView1.HotTracking = True
        ListView1.HoverSelection = False
          ListView1.ColumnHeaders.Add Text:="Row", Width:=64
            Set Wks = Sheets(1)
              For C = 1 To 13
            ListView1.ColumnHeaders.Add Text:=Wks.Cells(1, C).Text
            ComboBox1.AddItem Wks.Cells(1, C).Text
          Next C
        End Sub
    
     'SEARCH
      Dim Cnt As Long
     Dim Col As Variant
     Dim FirstAddx As String
     Dim FoundMatch As Range
     Dim LastRow As Long
     Dim R As Long
     Dim StartRow As Long
     Dim Wks As Worksheet
          StartRow = 2
         Set Wks = Sheets(1)
                Col = ComboBox1.ListIndex + 1
             If Col = 0 Then
                MsgBox "Please choose a category."
                Exit Sub
             End If
                   If TextBox1.Text = "" Then
              MsgBox "Please enter a search term."
              TextBox1.SetFocus
               Exit Sub
           End If
           
             LastRow = Wks.Cells(Rows.Count, Col).End(xlUp).Row
             LastRow = IIf(LastRow < StartRow, StartRow, LastRow)
                      Set Rng = Wks.Range(Wks.Cells(2, Col), Wks.Cells(LastRow, Col))
                        Set FoundMatch = Rng.Find(What:=TextBox1.Text, _
                                         After:=Rng.Cells(1, 1), _
                                         LookAt:=xlWhole, _
                                         LookIn:=xlValues, _
                                         SearchOrder:=xlByRows, _
                                         SearchDirection:=xlNext, _
                                         MatchCase:=False)
                                         
             
              If Not FoundMatch Is Nothing Then
                 FirstAddx = FoundMatch.Address
                 ListView1.ListItems.Clear
                              Do
                   Cnt = Cnt + 1
                   R = FoundMatch.Row
                   ListView1.ListItems.Add Index:=Cnt, Text:=R
                     For Col = 1 To 13
                       Set C = Wks.Cells(R, Col)
                       ListView1.ListItems(Cnt).ListSubItems.Add Index:=Col, Text:=C.Text
                    Next Col
                   Set FoundMatch = Rng.FindNext(FoundMatch)
                 Loop While FoundMatch.Address <> FirstAddx And Not FoundMatch Is Nothing
                 SearchRecords = Cnt
              Else
                 ListView1.ListItems.Clear
                 SearchRecords = 0
                 MsgBox "No match found for " & TextBox1.Text
              End If
              End Function
    
    
    Private Sub UserForm_Activate()
    
      Dim C As Long
      Dim i As Long
      Dim R As Long
      Dim Wks As Worksheet
              ListView1.View = lvwReport
        ListView1.HideSelection = False
        ListView1.FullRowSelect = True
        ListView1.HotTracking = True
        ListView1.HoverSelection = False
          ListView1.ColumnHeaders.Add Text:="Row", Width:=64
            Set Wks = Sheets(1)
              For C = 1 To 13
            ListView1.ColumnHeaders.Add Text:=Wks.Cells(1, C).Text
            ComboBox1.AddItem Wks.Cells(1, C).Text
          Next C
        End Sub
    Private Sub ListView1_Click()
        Dim Rw As Long
        On Error GoTo exit_proc
        Rw = Me.ListView1.SelectedItem
        ActiveWorkbook.FollowHyperlink Address:=ActiveSheet.Cells(Rw, 13).Value
    exit_proc:
        On Error Resume Next
    End Sub

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Fuzzy about fuzzy formula code

    Hello dmanatee,

    You cross posted this message at The Code Cage.

    Your post does not comply with Rule 8 of our Forum RULES. Cross-posting is when you post the same question in other forums on the web. You'll find people are disinclined to respond to cross-posts because they may be wasting their time solving a problem that has been solved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser)to the cross-post. Expect cross-posts without a link to be closed a message will be posted by the moderator explaining why. We are here to help so help us help you!

    Read this to understand why we ask you to do this
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    07-07-2010
    Location
    Montana, USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Fuzzy about fuzzy formula code

    wouldnt mind deleting my thread dont want to get in trouble especialy since i need help with this. how do you remove personal thrreads?

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Fuzzy about fuzzy formula code

    Hello dmanatee,

    You don't need to delete your post. We just ask that you include a reference or link to where your question has been posted elsewhere.

  5. #5
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Fuzzy about fuzzy formula code

    Hi dmanatee;
    Quote Originally Posted by dmanatee View Post
    I looked up something called fuzzy text that might work but I don’t understand how to get it into my current code and make it work.
    If you point the the "fuzzy text" that you found, then I might be able to better tell you how to implement it.

    But for now, this is where you would put it.
    Private Sub CommandButton1_Click()
        '..... code
        Set FoundMatch = Rng.Find(What:=TextBox1.Text, _
                After:=Rng.Cells(1, 1), _
                LookAt:=xlWhole, _
                LookIn:=xlValues, _
                SearchOrder:=xlByRows, _
                SearchDirection:=xlNext, _
                MatchCase:=False)
        '.... more code
    End Sub
    would probably be changed to

    Private Sub CommandButton1_Click()
        '..... code
        Set FoundMatch = Fuzzy_Text_Find(TextBox1.Text,....)
        '.... more code
    End Sub
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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