+ Reply to Thread
Results 1 to 3 of 3

Search Engine VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    05-13-2015
    Location
    Cebu, Philippines
    MS-Off Ver
    2010
    Posts
    2

    Re: Search Engine VBA

    I find this code better but i dont know how to have more columns in searching the fields and let more appears in the result..
    Sub SearchParts()
     Dim arrParts() As Variant
        Range("A7", "B" & Cells(Rows.CountLarge, "B").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("B2: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 2, 1 To 1)
        Do Until FoundCell Is Nothing
            arrPart(1, UBound(arrPart, 2)) = FoundCell.Offset(0, -1)
            arrPart(2, UBound(arrPart, 2)) = FoundCell.Value
            
            ReDim Preserve arrPart(1 To 2, 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
    Last edited by Leith Ross; 05-15-2015 at 07:23 PM. Reason: Added Code Tags

+ 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. [SOLVED] Excel Search Engine
    By Enehasd in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-14-2014, 10:41 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