Find and replace text within a cell and replace with all text from another cell

PeetG

New Member
Joined
Sep 1, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
G'day, I am new to this forum and pretty new to excel especially when it comes to coding so a step by step how to do would be great thanks.

I am trying to find and replace specific text "xxxxxxxxxx" within a cell C2 with all data from another cell B2; this needs to be done for all rows from 2-467

For example in cell C2 is a product description which I have inserted xxxxxxxxxx where I need the value from cell B2 to be inserted. (in place of xxxxxxxxxx)
*C2 is a product description with a email HTML enquiry button embedded, cell B2 is the related SKU, this will insert the SKU into the enquiry email.

A step by step how to do would be great thanks so much! Cheers Pete

products_2021-09-01_13-26_export_after_updated with HTML BO-E_Button.xlsm
ABC
1nameskudescription
2Battery Yuasa 12v10Ah AGM SLABAT011250<p><strong>Battery - OEM replacement lead acid, 12V 10ah. Deep Cycle Gel Matt Yuasa Battery OEM</strong><br></p><ul><li>12Eco / Racing - order 2 pieces 24v </li><li>16Eco / Racing, 20Lite - order 3 pieces 36v</li><li>20Eco / Racing - order 4 pieces 48v</li></ul><p><strong><span style="font-size: 16px;">Looking for more run time, upgrade to our</span></strong><br></p><p><strong><span style="font-size: 16px;"><a href="https://store60743265.company.site/products/LITHIUM-c111992516" target="_blank"><img src="https://s3.amazonaws.com/images.ecwid.com/images/wysiwyg/product/60743265/364950833/16293460045061364553986/button_lithium_power_paks_jpg" alt="Go to Lithium Power Paks"></a></span></strong><br></p><p><a href="mailto:peteg@oset.com.au?CC=info@oset.com.au&Subject=OSETBikesDownUnder%20Backorder%20or%20Parts%20Enquiry&Body=Dear%20OSET%20Bikes%20DownUnder%2C%0AWe%20would%20like%20to%20enquire%20about%3A%0A%0AITEM%3A%20xxxxxxxxxx%0A%0AFor%20our%0AOSET%20Bike%20Model%3A%0AYear%20Model%3A%0A%0AName%3A%0AMobile%3A" target="_blank"><img alt="Back Order Enquiry" src="https://dabuttonfactory.com/button.jpg?t=BACK-ORDER+or+ENQUIRE&f=Open+Sans-Bold&ts=14&tc=fff&hp=30&vp=10&c=11&bgt=unicolored&bgc=5ea83d" border="0" style="float: left; margin: 0px 10px 10px 0px;"></a></p><p><br></p>
3Battery OSET OEM Lithium-ion 48v, 20AhBAT022825<div><strong>OSET lithium-ion 48v, 20Ah, black 936 Wh. Black casing, on/off LED button, diagnostic and discharge/charge ports and vent.</strong><br> </div><p>Celxpert. Inc. UN carton 24.0R Jr 2017A+/ 24.0R 2017A+/ MX-10 2017A+/20R Mk2Li 2019c+</p><ul> <li>Can be fitted to 20 Eco and Racing from 2014+ with adaptor lead and charger - please request on order comment.</li> </ul><p><a href="mailto:peteg@oset.com.au?CC=info@oset.com.au&Subject=OSETBikesDownUnder%20Backorder%20or%20Parts%20Enquiry&Body=Dear%20OSET%20Bikes%20DownUnder%2C%0AWe%20would%20like%20to%20enquire%20about%3A%0A%0AITEM%3A%20xxxxxxxxxx%0A%0AFor%20our%0AOSET%20Bike%20Model%3A%0AYear%20Model%3A%0A%0AName%3A%0AMobile%3A" target="_blank"><img alt="Back Order Enquiry" src="https://dabuttonfactory.com/button.jpg?t=BACK-ORDER+or+ENQUIRE&f=Open+Sans-Bold&ts=14&tc=fff&hp=30&vp=10&c=11&bgt=unicolored&bgc=5ea83d" border="0" style="float: left; margin: 0px 10px 10px 0px;"></a></p><p><br> </p>
4Battery bag (36V) for 16E, 16R, 20LBAT031453Battery bag - suitable for 36V, nylon, black, 120 x 160 x 205mm, nylon & velcro. 16.0E/ 16.0R/ 20.0L </p><br/><p><a href="mailto:peteg@oset.com.au?CC=info@oset.com.au&Subject=OSETBikesDownUnder%20Backorder%20or%20Parts%20Enquiry&Body=Dear%20OSET%20Bikes%20DownUnder%2C%0AWe%20would%20like%20to%20enquire%20about%3A%0A%0AITEM%3A%20xxxxxxxxxx%0A%0AFor%20our%0AOSET%20Bike%20Model%3A%0AYear%20Model%3A%0A%0AName%3A%0AMobile%3A" target="_blank"><img alt="Back Order Enquiry" src="https://dabuttonfactory.com/button.jpg?t=BACK-ORDER+or+ENQUIRE&f=Open+Sans-Bold&ts=14&tc=fff&hp=30&vp=10&c=11&bgt=unicolored&bgc=5ea83d" style="float: left; margin: 0px 10px 10px 0px;" border="0"></a><br/></p>
5Battery bag (48V) for 20E, 20RBAT031454Battery bag - suitable for 48V, nylon, black, 120 x 220 x 220mm, nylon & velcro. 20.0E/ 20.0R </p><br/><p><a href="mailto:peteg@oset.com.au?CC=info@oset.com.au&Subject=OSETBikesDownUnder%20Backorder%20or%20Parts%20Enquiry&Body=Dear%20OSET%20Bikes%20DownUnder%2C%0AWe%20would%20like%20to%20enquire%20about%3A%0A%0AITEM%3A%20xxxxxxxxxx%0A%0AFor%20our%0AOSET%20Bike%20Model%3A%0AYear%20Model%3A%0A%0AName%3A%0AMobile%3A" target="_blank"><img alt="Back Order Enquiry" src="https://dabuttonfactory.com/button.jpg?t=BACK-ORDER+or+ENQUIRE&f=Open+Sans-Bold&ts=14&tc=fff&hp=30&vp=10&c=11&bgt=unicolored&bgc=5ea83d" style="float: left; margin: 0px 10px 10px 0px;" border="0"></a><br/></p>
6Battery parts - discharge port cover, blackBAT042583Battery parts - discharge port cover, black M24 For 20R24R MX10 </p><br/><p><a href="mailto:peteg@oset.com.au?CC=info@oset.com.au&Subject=OSETBikesDownUnder%20Backorder%20or%20Parts%20Enquiry&Body=Dear%20OSET%20Bikes%20DownUnder%2C%0AWe%20would%20like%20to%20enquire%20about%3A%0A%0AITEM%3A%20xxxxxxxxxx%0A%0AFor%20our%0AOSET%20Bike%20Model%3A%0AYear%20Model%3A%0A%0AName%3A%0AMobile%3A" target="_blank"><img alt="Back Order Enquiry" src="https://dabuttonfactory.com/button.jpg?t=BACK-ORDER+or+ENQUIRE&f=Open+Sans-Bold&ts=14&tc=fff&hp=30&vp=10&c=11&bgt=unicolored&bgc=5ea83d" style="float: left; margin: 0px 10px 10px 0px;" border="0"></a><br/></p>
7Battery OSET Lithium - charge port cover, silver M17BAT042584OSET Lithium - charge port cover, silver M17 knurled 20.0R Mk.2 Li 2019C+/24.0R Jr 2017A-2019C/ 24.0R 2017A+/ MX-10 2017A+ </p><br/><p><a href="mailto:peteg@oset.com.au?CC=info@oset.com.au&Subject=OSETBikesDownUnder%20Backorder%20or%20Parts%20Enquiry&Body=Dear%20OSET%20Bikes%20DownUnder%2C%0AWe%20would%20like%20to%20enquire%20about%3A%0A%0AITEM%3A%20xxxxxxxxxx%0A%0AFor%20our%0AOSET%20Bike%20Model%3A%0AYear%20Model%3A%0A%0AName%3A%0AMobile%3A" target="_blank"><img alt="Back Order Enquiry" src="https://dabuttonfactory.com/button.jpg?t=BACK-ORDER+or+ENQUIRE&f=Open+Sans-Bold&ts=14&tc=fff&hp=30&vp=10&c=11&bgt=unicolored&bgc=5ea83d" style="float: left; margin: 0px 10px 10px 0px;" border="0"></a><br/></p>
8Battery OSET Lithium - diagnostic port cover, silver M12BAT042585OSET Lithium - diagnostic port cover, silver M12 knurled 20.0R Mk.2 Li 2019C+/24.0R Jr 2017A-2019C/ 24.0R 2017A+/ MX-10 2017A+ </p><br/><p><a href="mailto:peteg@oset.com.au?CC=info@oset.com.au&Subject=OSETBikesDownUnder%20Backorder%20or%20Parts%20Enquiry&Body=Dear%20OSET%20Bikes%20DownUnder%2C%0AWe%20would%20like%20to%20enquire%20about%3A%0A%0AITEM%3A%20xxxxxxxxxx%0A%0AFor%20our%0AOSET%20Bike%20Model%3A%0AYear%20Model%3A%0A%0AName%3A%0AMobile%3A" target="_blank"><img alt="Back Order Enquiry" src="https://dabuttonfactory.com/button.jpg?t=BACK-ORDER+or+ENQUIRE&f=Open+Sans-Bold&ts=14&tc=fff&hp=30&vp=10&c=11&bgt=unicolored&bgc=5ea83d" style="float: left; margin: 0px 10px 10px 0px;" border="0"></a><br/></p>
9Brake Cable Front For 12.5RBRK011293Brake cable front For 12.5 Racing, 630*780mm. </p><br/><p><a href="mailto:peteg@oset.com.au?CC=info@oset.com.au&Subject=OSETBikesDownUnder%20Backorder%20or%20Parts%20Enquiry&Body=Dear%20OSET%20Bikes%20DownUnder%2C%0AWe%20would%20like%20to%20enquire%20about%3A%0A%0AITEM%3A%20xxxxxxxxxx%0A%0AFor%20our%0AOSET%20Bike%20Model%3A%0AYear%20Model%3A%0A%0AName%3A%0AMobile%3A" target="_blank"><img alt="Back Order Enquiry" src="https://dabuttonfactory.com/button.jpg?t=BACK-ORDER+or+ENQUIRE&f=Open+Sans-Bold&ts=14&tc=fff&hp=30&vp=10&c=11&bgt=unicolored&bgc=5ea83d" style="float: left; margin: 0px 10px 10px 0px;" border="0"></a><br/></p>
products_2021-09-01_13-26_expor
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi Pete, welcome to Mr.Excel!

Try this. It ads a new worksheet to your workbook and puts the changed data over there so you're able to see if the result is what you are looking for.

VBA Code:
Public Sub PeetG()

    Const PLACEHOLDER As String = "xxxxxxxxxx"

    Dim arr As Variant, rng As Range, i As Long

    With ThisWorkbook.ActiveSheet
        Set rng = .Range("B2:B" & .Cells(.Rows.Count, "B").End(xlUp).Row).Resize(, 2)
        arr = rng.Value2

        For i = LBound(arr, 1) To UBound(arr, 1)
            arr(i, 2) = VBA.Replace(arr(i, 2), PLACEHOLDER, arr(i, 1))
        Next i

        ' put data on a new sheet for safety reasons
        With .Parent.Worksheets.Add
            .Range("B2").Resize(UBound(arr, 1), UBound(arr, 2)).Value = arr
        End With

        ' put data where it came from
        ' rng.Value = arr

    End With
End Sub
 
Upvote 0
Solution
Hi Pete, welcome to Mr.Excel!

Try this. It ads a new worksheet to your workbook and puts the changed data over there so you're able to see if the result is what you are looking for.

VBA Code:
Public Sub PeetG()

    Const PLACEHOLDER As String = "xxxxxxxxxx"

    Dim arr As Variant, rng As Range, i As Long

    With ThisWorkbook.ActiveSheet
        Set rng = .Range("B2:B" & .Cells(.Rows.Count, "B").End(xlUp).Row).Resize(, 2)
        arr = rng.Value2

        For i = LBound(arr, 1) To UBound(arr, 1)
            arr(i, 2) = VBA.Replace(arr(i, 2), PLACEHOLDER, arr(i, 1))
        Next i

        ' put data on a new sheet for safety reasons
        With .Parent.Worksheets.Add
            .Range("B2").Resize(UBound(arr, 1), UBound(arr, 2)).Value = arr
        End With

        ' put data where it came from
        ' rng.Value = arr

    End With
End Sub
G'day GWteB,
That worked perfectly thanks very much, code is bit beyond me as I've never studied like HTML so appreciate you skills thanks!
Take care, cheers PeteG
 
Upvote 0
You're welcome and thanks for letting me know.
 
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