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