create a find button

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have created a custom user form to input data. Now I
need a macro that will search column A for example for
the value which is input into text box 1, and
furthermore, if the value entered in text box 1 is found,
I need the cell values for that specific record to be
displayed in the various text boxes on the user form for
editting, like for example I have a user form:

User Id, user name, user city
123, bob, kansas city

I need to search for 123 and return all values (123, bob,
kansas city) to text boxes on the user form so I can edit
them and ultimately save the changes.
 
Dim rng as Range
with Worksheets("Sheet1").Columns(1)
set rng = .find(what:=Userform1.Textbox1.Text, _
After:=Range(A65536), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End with
If not rng is Nothing then
With Userform1
.Textbox2.Text = rng.offset(0,1).Value
.Textbox3.Text = rng.Offset(0,2).Value
' and so forth
End with
Else
msgbox Userform1.Textbox1.Text & _
" was not found"
End If
 
Thank you for the repsonse...I am getting the error 1004

Method 'Range' of object '_Global' failed
 
Back
Top