+ Reply to Thread
Results 1 to 3 of 3

'Find' to find exact match only

  1. #1
    Registered User
    Join Date
    10-07-2011
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    13

    'Find' to find exact match only

    I have the following Macro and need it changed so that it will return the EXACT Match only.
    Can anyone help?


    Private Sub cmbFind_Click()
    Dim strFind As String 'what to find
    Dim FirstAddress As String
    Dim rSearch As Range 'range to search
    Set rSearch = Sheet1.Range("a6", Range("a65536").End(xlUp))
    Dim f As Integer

    imgFolder = ThisWorkbook.Path & Application.PathSeparator & "images" & Application.PathSeparator
    strFind = Me.TextBox1.Value 'what to look for

    With rSearch
    Set c = .Find(strFind, LookIn:=xlValues)
    If Not c Is Nothing Then 'found it
    c.Select
    With Me 'load entry to form
    .TextBox2.Value = c.Offset(0, 1).Value
    .TextBox3.Value = c.Offset(0, 2).Value
    .TextBox4.Value = c.Offset(0, 3).Value
    .cmbAmend.Enabled = True 'allow amendment or
    .cmbDelete.Enabled = True 'allow record deletion
    .cmbAdd.Enabled = False 'don't want to duplicate record
    If c.Offset(0, 4).Value = "ABYT" Then Me.CheckBox1 = True
    If c.Offset(0, 4).Value = "" Then Me.CheckBox1 = False
    If c.Offset(0, 5).Value = "ABRAYT" Then Me.CheckBox2 = True
    If c.Offset(0, 5).Value = "" Then Me.CheckBox2 = False
    If c.Offset(0, 6).Value = "ABWTT" Then Me.CheckBox3 = True
    If c.Offset(0, 6).Value = "" Then Me.CheckBox3 = False
    f = 0
    End With

    FirstAddress = c.Address
    Do
    f = f + 1 'count number of matching records
    Set c = .FindNext(c)
    Loop While Not c Is Nothing And c.Address <> FirstAddress
    If f > 1 Then
    Select Case MsgBox("There are " & f & " instances of " & strFind, vbOKCancel Or vbExclamation Or vbDefaultButton1, "Multiple entries")

    Case vbOK
    FindAll
    Case vbCancel
    'do nothing
    End Select
    Me.Height = frmMax

    End If
    Else: MsgBox strFind & " not listed" 'search failed
    End If
    End With
    If Sheet1.AutoFilterMode Then Sheet1.Range("A8").AutoFilter

    End Sub

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: 'Find' to find exact match only

    We are only allowed to help you after you have wrapped the VBA-code in code tags. See the forum rules.



  3. #3
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: 'Find' to find exact match only

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Would you like to say thanks? Please click the: " Add Reputation" button, on the grey bar below the post.

+ Reply to Thread

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