Results 1 to 20 of 20

Search and display all

Threaded View

tiny4725 Search and display all 05-22-2012, 12:12 PM
dilipandey Re: Search and display all 05-22-2012, 01:35 PM
tiny4725 Re: Search and display all 05-22-2012, 01:47 PM
dilipandey Re: Search and display all 05-22-2012, 01:51 PM
tiny4725 Re: Search and display all 05-22-2012, 02:05 PM
rvasquez Re: Search and display all 05-22-2012, 02:13 PM
tiny4725 Re: Search and display all 05-22-2012, 03:18 PM
rvasquez Re: Search and display all 05-22-2012, 03:54 PM
tiny4725 Re: Search and display all 05-23-2012, 07:13 AM
rkey Re: Search and display all 05-23-2012, 09:01 AM
tiny4725 Re: Search and display all 05-23-2012, 09:06 AM
rvasquez Re: Search and display all 05-23-2012, 09:11 AM
tiny4725 Re: Search and display all 05-23-2012, 10:05 AM
rvasquez Re: Search and display all 05-23-2012, 01:32 PM
tiny4725 Re: Search and display all 05-23-2012, 01:58 PM
tigeravatar Re: Search and display all 05-23-2012, 02:36 PM
tiny4725 Re: Search and display all 05-23-2012, 02:41 PM
tigeravatar Re: Search and display all 05-23-2012, 03:07 PM
tiny4725 Re: Search and display all 05-23-2012, 03:19 PM
rvasquez Re: Search and display all 05-23-2012, 03:27 PM
  1. #16
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Search and display all

    tiny4725,

    Attached is a modified version of your most recently posted workbook. I made several changes. First, I got rid of the 2nd userform, that was unnecessary. Here is the full code for the userform SearchForm:
    Private Sub btn_Search_Click()
        
        Dim rngFound As Range
        Dim strFirst As String
        
        If Len(Trim(Me.txt_SearchTerm.Text)) = 0 Then
            Me.txt_SearchTerm.SetFocus
            MsgBox "Must enter a search term", , "Search Error"
            Exit Sub
        End If
        
        Set rngFound = Cells.Find(Me.txt_SearchTerm.Text)
        If rngFound Is Nothing Then
            Me.txt_SearchTerm.SetFocus
            MsgBox "No items found contaning """ & Me.txt_SearchTerm.Text & """", , "Search Error"
            Exit Sub
        End If
        
        Me.lbx_Results.Clear
        strFirst = rngFound.Address
        Do While Not rngFound Is Nothing
            With Me.lbx_Results
                .AddItem rngFound.Address(0, 0)
                .List(.ListCount - 1, 1) = rngFound.Text
            End With
            Set rngFound = Cells.Find(Me.txt_SearchTerm.Text, rngFound)
            If rngFound.Address = strFirst Then Exit Do
        Loop
        
        Me.lbx_Results.SetFocus
        
    End Sub
    
    Private Sub lbx_Results_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
        
        Range(Me.lbx_Results.Value).Select
        Unload Me
        
    End Sub
    
    Private Sub UserForm_Terminate()
        
        Unload Me
        
    End Sub

    Changes made to the userform:
    • Changed the naming convention for the controls
    • Removed the frame
    • Setup a proper tab order
    • Made the search button the Default so that pressing enter causes that button's code to run
    • Double-clicking a search result item will still take you to that cell and close the userform
    • The listbox is now a 2 column listbox. The first column contains the cell address, the second column contains the dislpay text of the cell
    Attached Files Attached Files
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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