Lookup text in column A and change corresponding value in column B

dss28

Board Regular
Joined
Sep 3, 2020
Messages
165
Office Version
  1. 2007
Platform
  1. Windows
In Sheet1, I have data in range A5 to A15 and corresponding data in range B5 to B15.

If I enter a text in userform1.textbox1 ( eg corresponding to say text in cell A5) and another text in textbox2, the code should search this text in textbox1 in column A of the sheet1 and replace the cell B5 text with that of textbox2 text.

can anybody help please.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
You haven't said if A5 will always be linked to B5 (or A6 to B6 ect) or if A5 could be linked with B15 for example.
Possibly not the most elegant code but assuming the rows are always the same (ie A5 = B5) you could try the following by placing in the commandbutton code of your userform.

VBA Code:
Dim Lkfor As String, Chng As String
Dim Rng As Range, Ans As Range
Dim ws As Worksheet

Set ws = ActiveSheet 'can change this to your sheet name
Lkfor = TextBox1
Chng = TextBox2

Set Rng = ws.Range("A5:A15")     '''change to your specific range
Set Ans = Rng.Find(What:=Lkfor, LookIn:=xlValues, _
          LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
          MatchCase:=False, SearchFormat:=False)

          If Not Ans Is Nothing Then
               ws.Cells(Ans.Row, 2) = Chng
            Else
          End If
 
Upvote 0
Solution
thanks a lot
You haven't said if A5 will always be linked to B5 (or A6 to B6 ect) or if A5 could be linked with B15 for example.
Possibly not the most elegant code but assuming the rows are always the same (ie A5 = B5) you could try the following by placing in the commandbutton code of your userform.
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,301
Members
449,078
Latest member
nonnakkong

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