Results 1 to 6 of 6

Thread: Search form on work sheet

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member Ryan_Bernal's Avatar
    Join Date
    Dec 2012
    Posts
    37
    Rep Power
    0

    Search form on work sheet

    Hello!
    Can somebody help me on this?
    I am having hard time to populate text box without using input form.
    I want to use input form on worksheet which i used to search data on my worksheets (database 2010,database 2011, database 2012.. etc)
    Here is my code using input box which i pasted on standard module.
    Code:
    Public DSO As Object
    Public DstRow As Long
    Public DstWks As Worksheet
    Public SrcWks As Worksheet
    
    Private Sub FindKeyword(ByVal Keyword As String)
    
      Dim LastRow As Long
      Dim Result As Range
      Dim Rng As Range
      Dim StartRow As Long
        
        StartRow = 2
        LastRow = SrcWks.Cells(Rows.Count, "B").End(xlUp).Row
        LastRow = IIf(LastRow < StartRow, StartRow, LastRow)
        
          Set Rng = SrcWks.Cells(1, 1).CurrentRegion.Offset(1, 0)
          Set Rng = Rng.Resize(Rng.Rows.Count - 1)
          
            Set Result = Rng.Find(What:=Keyword, _
                                  After:=Rng.Cells(1, 1), _
                                  LookIn:=xlValues, _
                                  LookAt:=xlPart, _
                                  SearchOrder:=xlByColumns, _
                                  SearchDirection:=xlNext, _
                                  MatchCase:=False)
           A = Rng.Address
           If Not Result Is Nothing Then
             FirstAddx = Result.Address
               Do
                 If Not DSO.Exists(Result.Row) Then
                   DSO.Add Result.Row, DstRow
                   SrcWks.Rows(Result.Row).EntireRow.Copy Destination:=DstWks.Cells(DstRow, "A")
                   DstRow = DstRow + 1
                 End If
                 DstWks.Cells(DSO(Result.Row), Result.Column).Interior.ColorIndex = 6
                 Set Result = Rng.FindNext(Result)
               Loop While Not Result Is Nothing And Result.Address <> FirstAddx
           End If
          
    End Sub
    
    Public Sub FindKeywords()
    
      Dim Keys As Variant
      Dim Keyword As Variant
      Dim Keywords As Variant
      Dim Msg As String
      Dim R As Variant
      
        Set DstWks = Worksheets("View")
        Set SrcWks = Worksheets("Database 2010")
    
        If DSO Is Nothing Then
          Set DSO = CreateObject("Scripting.Dictionary")
          DSO.Comparemode = vbTextCompare
        End If
        
          Msg = "Please enter the keywords below. Separate multiple entries with a comma." _
              & " Wildcard characters * and ? can also be included."
        
          Keywords = InputBox(Msg)
        
            If Keywords <> "" Then
              DstRow = 21
              DstWks.UsedRange.Offset(20, 0).Clear
              Keywords = Split(Keywords, ",", Compare:=vbTextCompare)
                For Each Keyword In Keywords
                  FindKeyword (Keyword)
                Next Keyword
            Else
              Exit Sub
            End If
          
        Set DSO = Nothing
        Set Keywords = Nothing
        Sheets("View").Select
        Range("a21").Select
    End Sub
    Here is my work book:
    Thank you in Advance!
    Attached Files Attached Files

Similar Threads

  1. Replies: 1
    Last Post: 06-12-2013, 07:42 PM
  2. INPUT DATA FORM ON WORK SHEET
    By Ryan_Bernal in forum Excel Help
    Replies: 4
    Last Post: 12-30-2012, 05:56 PM
  3. Copy Row To A New Sheet If A Value Found In Adjacent Column
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 4
    Last Post: 08-17-2012, 05:42 PM
  4. work book format
    By Prabhu in forum Excel Help
    Replies: 1
    Last Post: 03-25-2012, 10:33 PM
  5. Replies: 2
    Last Post: 11-17-2011, 07:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •