I need to add a prefix to a text inside a cell

xROGERx

New Member
Joined
Dec 27, 2020
Messages
15
Office Version
  1. 2013
Platform
  1. Windows
Hello Mr.Excel family!

First of all...HAPPY NEW YEAR!

Secondly, as per the title, I need to add a prefix to a text inside a cell.

For example and, for the sake of argument, I have a list of male names in column A and I would like to add the prefix "Mr." (without quotations) to each and every single one of the names.

How can I achieve this?

Cheers and be well!
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
If you want to do it in the original cells, then try

VBA Code:
Sub Add_Prefix()
  Const Pref As String = "Mr. "
  
  With Range("a2", Range("A" & Rows.Count).End(xlUp))
    .Value = Evaluate(Replace(Replace("if(#="""","""",""^""&#)", "#", .Address), "^", Pref))
  End With
End Sub
 
Upvote 0
If you want to do it in the original cells, then try

VBA Code:
Sub Add_Prefix()
  Const Pref As String = "Mr. "
 
  With Range("a2", Range("A" & Rows.Count).End(xlUp))
    .Value = Evaluate(Replace(Replace("if(#="""","""",""^""&#)", "#", .Address), "^", Pref))
  End With
End Sub
I never thought of using the Evaluate function like this! Much faster than looping through cells. Smart! (y)
 
Upvote 0
****, I think I need to spend some time learning VBA.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,276
Members
449,075
Latest member
staticfluids

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