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

xROGERx

New Member
Joined
Dec 27, 2020
Messages
11
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!
 

Some videos you may like

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

mehidy1437

Active Member
Joined
Nov 15, 2019
Messages
270
Office Version
  1. 2013
Platform
  1. Windows
  2. Mobile
  3. Web
In cell B1, ="Mr."&A1
 
Solution

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
48,383
Office Version
  1. 365
Platform
  1. Windows
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
 

smozgur

BatCoder
Joined
Feb 28, 2002
Messages
1,343
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)
 

xROGERx

New Member
Joined
Dec 27, 2020
Messages
11
Office Version
  1. 2013
Platform
  1. Windows
****, I think I need to spend some time learning VBA.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,172
Messages
5,623,178
Members
415,955
Latest member
Footballtend

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
Top