Help with Substitute on Multiple variable

tbruce

Board Regular
Joined
Dec 9, 2013
Messages
77
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm trying to write a formula that will replace all the 3's with 4, all the 2's with 3, and all the 1's with 2, but need to do it in this order so it does the 3s first, then the 2s, then the 1s, that way it doesn't apply it twice to the number. The digit is in the first position from the left (e.g. 13029344, 23029344,33029344). Is there a way to do this with a formula? Any help would be appreciated.

Here is what I have for the first change which works, but can't figure out how to get the second and third variables changed with the same formula =SUBSTITUTE(B2,"3","4",1)
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Are you wanting to replace ALL matching digits or just the first (left-most) digit?
Does B2 contain: 13029344 and you want the leading replaced with a 2 to get 23029344 ? Is B2 numeric or alphanumeric?

If not, could you provide a specific example or three of what's in B2 and what you ultimately want?
 
Upvote 0
Try below,

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(B2,3,4),2,3),1,2)
 
Upvote 0
If mehidy's solution is what you want, I'd suggest placing 1* after the = sign to get a numeric result if you want a numeric result.
 
Upvote 0
This at first looks to work, but for some reason this is also changing the 3rd digit from the left when it is 1,2,3. The only digit I want to change in in the 1st position from the left.
 
Upvote 0
try:

Code:
=1*SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(B2,3,4,1),2,3,1),1,2,1)
 
Upvote 0
Yea that didn't work either - it's still changing the #3 digit. 30139 is being changed to 40239, so it did the first digit but also the 3rd digit too since it was a 1.
 
Upvote 0
Looks like the ,1 is replacing the first instance of the number versus in the first position of the value.
 
Upvote 0
See if this is, what you are looking for or not?
Book1
ABCD
13013940139
22013930139
31013920139
43013940139
53013940139
Sheet1
Cell Formulas
RangeFormula
D1:D5D1=IF(LEFT(A1,1)="3",SUBSTITUTE(A1,3,4,1),IF(LEFT(A1,1)="2",SUBSTITUTE(A1,2,3,1),IF(LEFT(A1,1)="1",SUBSTITUTE(A1,1,2,1),"")))
 
Upvote 0
Perhaps this?

20 09 09.xlsm
AB
13013940139
22013930139
31013920139
43013940139
53013940139
65555555555
Substitute
Cell Formulas
RangeFormula
B1:B6B1=--REPLACE(A1,1,1,LEFT(A1,1)+OR(--LEFT(A1,1)={1,2,3}))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,732
Members
449,093
Latest member
Mnur

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