+ Reply to Thread
Results 1 to 5 of 5

Refining Famous Search Engine

Hybrid View

  1. #1
    Registered User
    Join Date
    11-19-2014
    Location
    são paulo
    MS-Off Ver
    ms o 2010
    Posts
    4

    Refining Famous Search Engine

    Well,

    hello guys. I want to make this search engine code a little bit better. I have two main concerns:

    1) If the user writes two or more words, e.g., sun moon the search engine will look for all the Data in column B with the word sun and/or moon. It means, instead of using the exactly word (sun moon) written in cells(2,2) it would search separately for each word.

    2) This is far more important than the first one: I would like for similar words in the search engine. For example, if the user searches for sum it will return sun anyway, because the words are very similar. But the question is: what is similar? Well, I am asking for any help in a code that I don't have the slightest idea of how to do it.

    Thank you very much, in my next post I will have studied more about VBA.

    Sub SearchParts()
     Dim arrParts() As Variant
        Range("A7", "D" & Cells(Rows.CountLarge, "D").End(xlDown).Row).Clear
        arrParts = FindParts(CStr(Trim(Cells(2, 2))))
        Range("A7").Resize(UBound(arrParts, 2), UBound(arrParts)) = _
            WorksheetFunction.Transpose(arrParts)
    End Sub
    Private Function FindParts(PartNumber As String) As Variant
    Dim ws As Worksheet
    Dim FoundCell As Range
    Dim LastCell As Range
    Dim rngParts As Range
    Dim FirstAddr As String
    Dim arrPart() As Variant
    
        Set ws = Worksheets("Data")
        Set rngParts = ws.Range("B4:B" & ws.Cells(Rows.CountLarge, "B").End(xlUp).Row)
    
        With rngParts
            Set LastCell = .Cells(.Cells.Count)
        End With
    
        Set FoundCell = rngParts.Find(What:=PartNumber, After:=LastCell, LookAt:=xlPart)
    
        If Not FoundCell Is Nothing Then
            FirstAddr = FoundCell.Address
        End If
        
        ReDim arrPart(1 To 4, 1 To 1)
        Do Until FoundCell Is Nothing
            arrPart(1, UBound(arrPart, 2)) = FoundCell.Offset(0, -1)
            arrPart(2, UBound(arrPart, 2)) = FoundCell.Value
            arrPart(3, UBound(arrPart, 2)) = FoundCell.Offset(0, 1)
            arrPart(4, UBound(arrPart, 2)) = FoundCell.Offset(0, 2)
            
            ReDim Preserve arrPart(1 To 4, 1 To UBound(arrPart, 2) + 1)
    
            Set FoundCell = rngParts.FindNext(After:=FoundCell)
            If FoundCell.Address = FirstAddr Then
                Exit Do
            End If
        Loop
        FindParts = arrPart
    End Function

  2. #2
    Registered User
    Join Date
    11-19-2014
    Location
    são paulo
    MS-Off Ver
    ms o 2010
    Posts
    4

    Re: Refining Famous Search Engine

    Well, I did this

     Dim cont As Long
     
        Range("A7", "D" & Cells(Rows.CountLarge, "D").End(xlDown).Row).Clear
        sep = Split(Cells(2, 2), " ")
        
        For cont = LBound(sep) To UBound(sep)
        arrParts = FindParts(CStr(Trim(sep(cont))))
        Range("A7").Resize(UBound(arrParts, 2), UBound(arrParts)) = _
            WorksheetFunction.Transpose(arrParts)
        Next
        
    End Sub
    But the result is being rewritten. Any suggestions?

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Refining Famous Search Engine

    This line of decides the type of match you are looking for

    Set FoundCell = rngParts.Find(What:=PartNumber, After:=LastCell, LookAt:=xlPart) 'Partial match
    
    Set FoundCell = rngParts.Find(What:=PartNumber, After:=LastCell, LookAt:=xlWhole) 'exact match

  4. #4
    Registered User
    Join Date
    11-19-2014
    Location
    são paulo
    MS-Off Ver
    ms o 2010
    Posts
    4

    Re: Refining Famous Search Engine

    Second question is already working.

    Thank you AB33

  5. #5
    Registered User
    Join Date
    11-19-2014
    Location
    são paulo
    MS-Off Ver
    ms o 2010
    Posts
    4

    Re: Refining Famous Search Engine

    First question solved:

     Dim i As Integer
    
        Range("A7", "D" & Cells(Rows.CountLarge, "D").End(xlDown).Row).Clear
        sep = Split(Cells(2, 2), " ")
        
        i = 1
        
        For cont = LBound(sep) To UBound(sep)
        arrParts = FindParts(CStr(Trim(sep(cont))))
        
        If IsEmpty(Cells(6 + i, 1)) Then
            Cells(6 + i, 1).Resize(UBound(arrParts, 2), UBound(arrParts)) = _
            WorksheetFunction.Transpose(arrParts)
        Else
            Do Until IsEmpty(Cells(6 + i, 1))
                i = i + 1
            Loop
            
            Cells(6 + i, 1).Resize(UBound(arrParts, 2), UBound(arrParts)) = _
            WorksheetFunction.Transpose(arrParts)
            
        End If
            
        Next
        
    End Sub

+ 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 Engine
    By kmcclintic in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-28-2014, 07:56 AM
  2. search engine in excel
    By ejlersen in forum Excel Formulas & Functions
    Replies: 20
    Last Post: 04-14-2013, 06:23 AM
  3. Search engine
    By Ryan_Bernal in forum Excel General
    Replies: 8
    Last Post: 12-24-2012, 03:14 AM
  4. Search engine
    By zplugger in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 04-11-2009, 01:16 PM
  5. Developing Search Engine to search several Excel sheets
    By cruiser102 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-26-2009, 09:30 AM

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