If Formula

kbendelac

New Member
Joined
Aug 9, 2020
Messages
38
Office Version
  1. 2019
Platform
  1. Windows
I am looking to create a formula that would remove the first 2 digits of a series and if a text string contains the word Anjou replace with 78 or Moncton replace with 83.

As an example:
Cell A2 contains 704705041 and B2 will need to read 784705041/834705041 where 70 (first 2 digits of A2) will be replaced with either 78 for Anjou or 83 for Moncton in B2

1720106615297.png
 

Attachments

  • 1720106578537.png
    1720106578537.png
    23.7 KB · Views: 2

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Please try
=IF(ISNUMBER(SEARCH("Anjou",D2)),REPLACE(A2,1,2,78),IF(ISNUMBER(SEARCH("Moncton",D2)),REPLACE(A2,1,2,83),A2))
 
Upvote 0
Another option
Excel Formula:
=REPLACE(A2,1,2,IF(ISNUMBER(SEARCH("Anjou",D2)),78,IF(ISNUMBER(SEARCH("Moncton",D2)),83,"")))
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
Another option
Excel Formula:
=REPLACE(A2,1,2,IF(ISNUMBER(SEARCH("Anjou",D2)),78,IF(ISNUMBER(SEARCH("Moncton",D2)),83,"")))

I think this will chop off the first 2 characters if neither text is found.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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