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
 

Some videos you may like

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,974
Office Version
  1. 2013
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,165
Messages
5,594,622
Members
413,918
Latest member
Mikey_C

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
Top