Select a specific value from text box and search in a column of excel

amarjeeth

New Member
Joined
Sep 7, 2013
Messages
1
Dear All,

I have a worksheet "database" which is database of patient information in each row, in column H I have the "pateint IP number" I have a userform for search and copy. The textbox in the userform is "search_tb1", where I would input the required IP number and search in column H for a match, which should intern select the entire row of this selected cell and paste in another worksheet "preview" in row 2.

Can you please help me achieve this?

Thanks for your help.

Amar
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
This code is to be copied to the UserForm code module and will run when the TextBox is double clicked.
Code:
Private Sub search_tb1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, rng As Range, fVal As Range
Set sh1 = Sheets("database")
Set sh2 = Sheets("preview")
If Me.search_tb1.Value <> "" Then
    lr = sh1.Cells(Rows.Count, "H").End(xlUp).Row
    Set rng = sh1.Range("H2:H" & lr)
        Set fVal = rng.Find(Me.search_tb1.Value, LookIn:=xlValues)
            If Not fVal Is Nothing Then
                fVal.EntireRow.Copy sh2.Cells(Rows.Count, 1).End(xlUp)(2)
            End If
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,591
Members
449,089
Latest member
Motoracer88

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