Results 1 to 10 of 10

Fixing code for search engine for whole workbook

Threaded View

  1. #10
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,994

    Re: Fixing code for search engine for whole workbook

    an alternative:
    Option Explicit
    Sub MyFind()
        Dim Message         As String, _
            Title           As String, _
            Default         As String, _
            SearchString    As String, _
            Location        As String, _
            Report          As String, _
            Results         As Range, _
            WS              As Worksheet, _
            NotFoundCount   As Long, _
            Ndx             As Variant, _
            temp            As String
        
        Message = "Enter your query!" ' Set prompt.
        Title = "What are you looking for?" ' Set title.
        Default = "" ' Set default.
        temp = "hhhhhhhhhhhhhhh"
        Set WS = Sheets("list")
        
        SearchString = Trim(InputBox(Message, Title, Default))
        
            With WS.Range("A1").CurrentRegion
                Set Results = .Find(SearchString, _
                                MatchCase:=False, _
                                LookAt:=xlPart, _
                                LookIn:=xlValues)
                    
                If Not Results Is Nothing Then
                    Location = Results.Address(0, 0)
                    Do
                        For Each Ndx In Array("B", "A", "H", "I", "J", "K")
                            RSet temp = .Cells(Results.Row, Ndx).Value
                            Default = Default & IIf(Default <> "", vbTab, "") & temp
                        Next Ndx
                        Report = Report & IIf(Report <> "", vbCrLf, "") & Default
                        Default = ""
                       
                        Set Results = .FindNext(Results)
                    Loop While Not Results Is Nothing And Results.Address(0, 0) <> Location
                Else
                    NotFoundCount = NotFoundCount + 1
                End If
            End With
        
        If NotFoundCount = ThisWorkbook.Sheets.Count Then
            MsgBox Chr(34) & SearchString & Chr(34) & vbCrLf _
            & "was not found", vbCritical + vbOKOnly
        Else
            For Each Ndx In Array("B", "A", "H", "I", "J", "K")
                RSet temp = WS.Cells(1, Ndx).Value
                Default = Default & IIf(Default <> "", vbTab, "") & temp
            Next Ndx
                Default = Default & vbCrLf & WorksheetFunction.Rept("¯", Len(Default) + 5 * Ndx) & vbCrLf
                Report = Default & Report
            MsgBox Report
        End If
    End Sub
    assumes only one listing sheet.
    Attached Files Attached Files

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