Userforms and Search

jabryantiii

Board Regular
Joined
Sep 18, 2009
Messages
129
I have the following code set up in a user form, currently when the search function is called it takes me to the sheet where the data is being pulled from. How do i change it so that it doesnt take me to that sheet and only populates to the userform?

Code:
Private Sub cmdFind_Click()
    Dim strFind, FirstAddress As String   'what to find
    Dim rSearch As Range  'range to search
    With Sheet3
        Set rSearch = .Range("A1", .Cells(.Rows.Count, "A").End(xlUp))
    End With
    strFind = Me.txt1stName.Value    'what to look for
    Dim f      As Integer
    With rSearch
        Set c = .Find(strFind, LookIn:=xlValues)
        If Not c Is Nothing Then    'found it
            Application.GoTo c
            With Me    'load entry to form
                .txtInitial.Value = c.Offset(0, 1).Value
                .txt2ndName.Value = c.Offset(0, 2).Value
                .txtAddress1.Value = c.Offset(0, 4).Value
 
                .cmdAdd.Enabled = False      'don't want to duplicate record
                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
                MsgBox "There are " & f & " instances of " & strFind
                Me.Height = frmMax
            End If
        Else: MsgBox strFind & " not listed"    'search failed
        End If
    End With
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,214,566
Messages
6,120,257
Members
448,952
Latest member
kjurney

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top