I need help writing code for a search and replace text box.

Jayliam

New Member
Joined
May 12, 2015
Messages
31
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I would like someone to help with writing a code to be able to enter a number in one text box and have the program use that number to search find it in column A and then display the correlating column B data in another text box. If this is not possible please let me know.

Ian
 
Try:
Code:
Sub M1()

Dim str As Variant
Dim rng As range
Dim x  As Long

str = InputBox("Enter value: ")

x = Cells(rows.count, 1).End(xlUp).row
On Error Resume Next
Set rng = Cells(1, 1).Resize(x).find(what:=str, LookIn:=xlValues, lookat:=xlWhole)
On Error GoTo 0

If Not rng Is Nothing Then
    MsgBox "Associated value with: " & str & " is" & vbCrLf & vbCrLf & rng.Offset(, 1).value, vbOKOnly, "Value found"
    Set rng = Nothing
Else
    MsgBox "Value: " & str & " is not found", vbExclamation, "Value not found"
End If

End Sub
 
Last edited:
Upvote 0
Thank you for your response. Can you please explain what the M1() is and what I need to do with it?
 
Upvote 0
M1 is the name of the procedure (script) you wanted written. You need to insert this script into a module and then run it.

You can search online how to run a macro in Excel.
 
Upvote 0

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