REDUCE with SUBSTITUTE not quite working

tigerzen

Board Regular
Joined
Mar 8, 2023
Messages
209
Office Version
  1. 365
Platform
  1. Windows
Replacing.xlsx
ABCDEFGH
1Should readTable for changes
2CourseCourseOldNew
3Adv Dip Sci Advanced Diploma ScienceAdvAdvancedAdvanced Diploma Science
4As Deg BusinessAssociate Degree BusinessDipDiplomaAssociate Degree Business
5D Bus Diploma BusinessD Diploma Diploma Business
6Cer MathsCertificate MathsCerCertificateCertificate Maths
7D SciDiploma ScienceAsAssociateDiploma Sci
8DegDegree
9Bus Business
10Sci Science
Sheet1
Cell Formulas
RangeFormula
H3:H7H3=REDUCE(A3,Table1[Old],LAMBDA(a,v,SUBSTITUTE(a,v,OFFSET(v,0,1))))


This mainly works except for the cell in yellow. To get around replacing issues I've entered some of the old values with a trailing space. I was getting Businessiness before using the trailing space. There's probably an easy fix for this but it's beyond me.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Delete the formulas from column H and put the following formula in H3:

=REDUCE(A3:A7,Table1[Old],LAMBDA(a,v,SUBSTITUTE(a,v,OFFSET(v,0,1))))

In automatic it will set all the values from H3 to H7.

This is the problem:
1727412848523.png
 
Last edited:
Upvote 0
Delete the formulas from column H and put the following formula in H3:

=REDUCE(A3:A7,Table1[Old],LAMBDA(a,v,SUBSTITUTE(a,v,OFFSET(v,0,1))))

In automatic it will set all the values from H3 to H7.

This is the problem:
View attachment 117383
Thanks Dante, I did try the same formula with the array, the problem is still when to include a trailing space and when not to. The Bus entry in E9 contains a trailing space, without it I get Businessiness in H4
 
Upvote 0
Hello, alternatively, you could go with:

Excel Formula:
=LET(
a,TEXTSPLIT(A3," "),
b,XLOOKUP(a,Table1[Old],Table1[New]),
c,IF(ISNA(b),a,b),
TEXTJOIN(" ",,c))
 
Upvote 0
Hello, alternatively, you could go with:

Excel Formula:
=LET(
a,TEXTSPLIT(A3," "),
b,XLOOKUP(a,Table1[Old],Table1[New]),
c,IF(ISNA(b),a,b),
TEXTJOIN(" ",,c))
Hello Hagia_sofia, your formula works! I won't even pretend that I understand it though but thank you for coming up with a formula that works in every situation.

If there is an easier way to achieve the same outcome I'd appreciate it but otherwise I'll try and get my head around this formula.
 
Upvote 0
Many thanks for the feedback. It is not too complicated after all: step a splits original text string into individual elements, step b compares these elements against the lookup table, step c is there to preserve the original elements that are not in the look up table (i.e. those parts that originally are not shortcuts), and the last step joins everything back together. There might be an easier way to do it so maybe somebody will post it...
 
Upvote 0
the problem is still when to include a trailing space and when not to

Do not include any extra space in the cells. We solve it in the formula this way:

Put the following formula in H3, in automatic it will set all the values from H3 to H7.
Excel Formula:
=REDUCE(A3:A7&" ",Tabla1[Old],LAMBDA(a,v,SUBSTITUTE(a&" ",v&" ",OFFSET(v,0,1)&" ")))

ex:
1727457987169.png


🤗
 

Attachments

  • 1727457638307.png
    1727457638307.png
    46.3 KB · Views: 1
Last edited:
Upvote 0
I made a small correction in the formula, in the table name:

Rich (BB code):
=REDUCE(A3:A7&" ",Table1[Old],LAMBDA(a,v,SUBSTITUTE(a&" ",v&" ",OFFSET(v,0,1)&" ")))
 
Upvote 0
Here is another option to not use the volatile OFFSET function:

VBA Code:
=REDUCE(A3:A7&" ",Table1[Old],LAMBDA(a,v,SUBSTITUTE(a&" ",v&" ",VLOOKUP(v,Table1,2,0)&" ")))
 
Upvote 0
Solution
Thanks Dante, that works beautifully! And I really appreciate the Vlookup alternative to Offset.
 
Upvote 1

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

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