Excel vba coding to replace each string to different text or nest formula?

AS12Excel

New Member
Joined
Feb 16, 2018
Messages
7
Hello,
I'm trying to replace 100 cells in a column that has different values. The result will be in another column that identify the first letter of that cell and replace with one the 3 names in all selected rows (Mary, Thomas, Hilton). I believe a VBA code would be easier than a nest formula itself?

per example:

Existent cells:
M0779
T1524
H0084

Desired result
Mary
Thomas
Hilton

Thanks for helping!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Assuming original data in column A & results in column B, try this in a copy of your workbook.
Code:
Sub ReplaceWithName()
  With Range("A1", Range("A" & Rows.Count).End(xlUp))
    .Offset(, 1).Value = Evaluate(Replace("if(#="""","""",iferror(choose(search(left(#,1),""MTH""),""Mary"",""Thomas"",""Hilton""),#))", "#", .Address))
  End With
End Sub

The worksheet formula equivalent probably isn't as bad as you thought:

Excel Workbook
AB
1DataResult
2M0779Mary
3
4T1524Thomas
5H0084Hilton
6xczxcxczxc
Replace
 
Upvote 0

Forum statistics

Threads
1,216,110
Messages
6,128,892
Members
449,477
Latest member
panjongshing

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