0

In Excel, how can I replace text in a cell containing a particular string, with another string?

The original values look like this

802-2553
802-1753
802-5589
103-4569
103-54879
303-1542
303-6589
502-1236

What I'm trying to do is replace all cells with 802 as the first 3 characters with the Text Vehicle Loans, 103 with the text Home Loans and 303 with Saving Accounts, 502 with Other Loans

So the end result is

Vehicle Loans
Vehicle Loans
Vehicle Loans
Home Loans
Home Loans
Savings Accounts
Savings Accounts
Other Loans

I tried with the Substitute Function, but it seems that function won't work for something like this.

What other way to achieve this?

3 Answers 3

1

Try combining IF and LEFT:

=IF(LEFT(A1,3)="802","Vehicle loans", IF(LEFT(A1,3)="103","Home loans",IF(LEFT(A1,3)="303","Saving account",IF(LEFT(A1,3)="502","Other account","Unknown account"))))

Use in an adjoining cell and copy and paste values.

Sign up to request clarification or add additional context in comments.

Comments

1

I wquld use a formula and a lookup table.

Construct your ReplacementTable

Then, with your data starting in A2, try this formula:

=VLOOKUP(--LEFT(A2,FIND("-",A2)-1),ReplacementTable,2,FALSE)

ReplacementTable Refers To: =Sheet1!$E$2:$F$6

Since I entered the "prefix" as a number in the lookup table, I have to use a number to do the lookup -- hence the double unary -- preceding the LEFT function in the formula.

enter image description here

Comments

0

Both the answers above are excellent.

Or you could just use search and replace. It's quick and dirty.

  1. Ctrl-H
  2. Find what: "802-"
    Put the hyphen in so that it doesn't find values within the cell.

  3. Replace with: "Vehicle Loans"

  4. Repeat for the other codes you want to replace: 103, 303, etc

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.