Mass SUBSTITUTE using a list?

ArodSnaux

New Member
Joined
Nov 1, 2018
Messages
2
Is it possible to use SUBSTITUTE (or some other method) using a list of inputs?

For example, my target cell contains the string

[TABLE="width: 500"]
<tbody>[TR]
[TD] I love Apples, I hate Orange, my Banana, my Grape[/TD]
[/TR]
</tbody>[/TABLE]

and on another sheet I have a ranged list:

[TABLE="width: 500"]
<tbody>[TR]
[TD]Apple[/TD]
[TD]Red[/TD]
[/TR]
[TR]
[TD]Orange[/TD]
[TD]Orange[/TD]
[/TR]
[TR]
[TD]Banana[/TD]
[TD]Yellow[/TD]
[/TR]
[TR]
[TD]Grape[/TD]
[TD]Green[/TD]
[/TR]
</tbody>[/TABLE]


I'm looking for way to get a result of

[TABLE="width: 500"]
<tbody>[TR]
[TD][TABLE="width: 500"]
<tbody>[TR]
[TD]I love Red, I hate Orange, my Yellow, my Green[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]


Obviously I could nest SUBSTITUTE, by my real list contains over 200 entries!

I tried this: =SUBSTITUTE(GF39,NAMES!A:A,NAMES!C:C) but to no avail.

Help? I'm programmer so I can always fall back to VBA, but I figured you guys might know a built-in way to do this.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Okay I broke down and learned enough VBA to do it:

Code:
Function SUBSTITUTEMANY(myStr As String, lookupRange As Range)    


    Dim cell As Range
    Dim col As Range
    
    Set col = lookupRange.Columns(1).Cells
    
    For Each cell In col
        newStr = Application.WorksheetFunction.VLookup(cell.Value, lookupRange, 2, False)
        Debug.Print newStr
        myStr = Application.Substitute(myStr, cell.Value, newStr)
    Next cell


    SUBSTITUTEMANY = myStr


End Function

After that its just a matter of typing something like this in a cell:

=SUBSTITUTEMANY(A1,[MyTable.xlsm]Sheet1!$A$1:$B$24)
 
Upvote 0

Forum statistics

Threads
1,223,967
Messages
6,175,667
Members
452,666
Latest member
AllexDee

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