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

I love Apples, I hate Orange, my Banana, my Grape

<tbody>
</tbody>

and on another sheet I have a ranged list:

AppleRed
OrangeOrange
BananaYellow
GrapeGreen

<tbody>
</tbody>


I'm looking for way to get a result of

I love Red, I hate Orange, my Yellow, my Green

<tbody>
</tbody>

<tbody>
</tbody>


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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
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,215,421
Messages
6,124,806
Members
449,191
Latest member
rscraig11

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