Replace specific text with value from another cell

capo4410

New Member
Joined
Feb 20, 2019
Messages
14
Hello all,

I’m trying to create a macro, but am having some difficulties. I am looking to search a cell (“K2”) for the word Location. Once found I would like to replace that word with the contents located in cell “L2”. This sheet will have many rows and the information within column L will always different. I thought a find replace code would be sufficient, but couldn’t it to work when taking data from a different cell.

Any help would be greatly appreciated. Thank you!
 
Last edited:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Try this

Code:
Sub Replace_specific_text()
    Dim c As Range
    For Each c In Range("K1", Range("K" & Rows.Count).End(xlUp))
        n = InStr(1, LCase(c.Value), LCase("Location"))
        If n > 0 Then c.Value = Left(c.Value, n - 1) & c.Offset(0, 1).Value & Mid(c.Value, n + 8)
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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