+ Reply to Thread
Results 1 to 5 of 5

Thread: Userforms: Textbox Searches

  1. #1
    Registered User
    Join Date
    09-05-2011
    Location
    St. John's, Canada
    MS-Off Ver
    Excel 2010
    Posts
    71

    Userforms: Textbox Searches

    Hello Everyone,

    I've been working the past little while to create a Excel Acronym Search Engine. Everyone thus far has been a great help. I'm almost done. I'm currently combating one more issue. in the sheet labled "Acronym Search Engine" , of the attached workbook, I have created multiple text boxes. These text boxes display the search results from whats typed into the "Acronym" Text box. Now I want to deal with having multiple acronyms, I want them to display in the subsequent text boxes. I've been playing with the "SearchNext" and "SearchPrevious" but with now luck.

    Does anyway have any idea how I could display multiple definitions if they did exists?

    I've attached a workbook for clarification.

    Thank you so much everyone
    Attached Files Attached Files
    Last edited by ashleys.nl; 10-14-2011 at 11:53 AM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    11,351

    Re: Userforms: Textbox Searches

    how about this.

    Private Sub TextBox1_Change()
    
        Dim lngIndex As Long
        Dim strAcronym As String
        Dim rngFind As Range
        Dim strFirstAddress As String
        Dim strName As String
        Const NTEXTBOXES = 25
        
    '    On Error Resume Next
    'Empty Text Boxes'
        For lngIndex = 2 To NTEXTBOXES
            Me.Shapes("Textbox" & lngIndex).OLEFormat.Object.Object.Text = ""
        Next
    
        lngIndex = 2
        strAcronym = Me.Shapes("Textbox1").OLEFormat.Object.Object.Text
        If Len(strAcronym) > 0 Then
            strAcronym = strAcronym & "*"
            With Worksheets("Acronym Database").Range("A1").CurrentRegion.Columns(1)
                Set rngFind = .Find(What:=strAcronym)
                If Not rngFind Is Nothing Then
                    strFirstAddress = rngFind.Address
                    Do
                        Me.Shapes("Textbox" & lngIndex).OLEFormat.Object.Object.Text = rngFind.Offset(0, 1).Value
                        Me.Shapes("Textbox" & lngIndex + 1).OLEFormat.Object.Object.Text = rngFind.Offset(0, 2).Value
                        Me.Shapes("Textbox" & lngIndex + 2).OLEFormat.Object.Object.Text = rngFind.Offset(0, 3).Value
                        
                        lngIndex = lngIndex + 3
                        If lngIndex > NTEXTBOXES Then Exit Do
                        Set rngFind = .FindNext(rngFind)
                    Loop While Not rngFind Is Nothing And rngFind.Address <> strFirstAddress
                End If
            End With
        End If
    End Sub
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    09-05-2011
    Location
    St. John's, Canada
    MS-Off Ver
    Excel 2010
    Posts
    71

    Re: Userforms: Textbox Searches

    WOW! that's more than I could ask for! thank you soo much! works like a charm!

  4. #4
    Registered User
    Join Date
    09-05-2011
    Location
    St. John's, Canada
    MS-Off Ver
    Excel 2010
    Posts
    71

    Re: Userforms: Textbox Searches

    This works great, but I notice that when I use acronyms that only contain two letters I get a lot of matches because the code is searching in such a way that it doesn't have to be an exact match.

    What would I change in the code to make it look for exact matches only ?

    For example if I search "IM", I don't want to see the result for "FIM" or "IMS" ?

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    11,351

    Re: Userforms: Textbox Searches

    If you add the LookAt argument you can restrict it to a match with string begining with the letters. So AF would return these 3, AFC,AFD,AFE

                Set rngFind = .Find(What:=strAcronym, Lookat:=xlWhole)
    If you only what exact matches then also alter this line by commenting out the wildcard search

            strAcronym = strAcronym '& "*"
    Cheers
    Andy
    www.andypope.info

+ Reply to Thread

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.2.0