How to Add Prefix or suffix to Cell

This post will guide you how to add common prefix or suffix to all cells or the range of cells in your worksheet in Excel. How do I add the same prefix or suffix to a range of cells without any changing the existing numbers or text in the range. How to add prefix or suffix to all cells with Excel VBA Macro.

Assuming that you have a list of data that you want to add common text to the starting position of all cells, of course, you can do it by manually, but it will consume lots of time and it is not a good idea. And you can use the concatenate operator, the CONCATENATE function to create a new Excel formula to add prefix or suffix to the range of cells that you selected. Or you can write a new Excel VBA Macro to achieve the same result.

Method 1: Using Concatenation Operator to add prefix or suffix

If you want to add prefix or same text to the starting of all cells in your range, you can use the Concatenation operator to build a formula, for example, you want to add same text “excelhow” to all cells in range A1:A4, then you can use the following formula:

="excelhow"&A1

Ether this formula in a blank cell, such as: B1, then drag the AutoFill Handle down to other cells to apply this formula.

add prefix or suffix 1

If you want to add suffix to all cells with concatenation operator, you can use the following formula:

=A1&"excelhow"

add prefix or suffix2

You will see that all cells are added the same prefix text in your worksheet.

Method 2: Using concatenation function to add prefix

To add prefix or suffix text or number to the range of cells with concatenation function, you can wirte down the following formula:

=CONCATENATE("excelhow",A1)
or
=CONCATENATE(A1,"excelhow")

add prefix or suffix3

Method 3: Using Excel VBA Macro to add prefix

You can also use the following VBA Macro code to add prefix or suffix in your worksheet in Excel.  Let’s see the below steps:

1# click on “Visual Basic” command under DEVELOPER Tab.

Get the position of the nth using excel vba1

2# then the “Visual Basic Editor” window will appear.

3# click “Insert” ->”Module” to create a new module

convert column number to letter3

4# paste the below VBA code into the code window. Then clicking “Save” button.

add prefix or suffix4

Sub AddPrefixToCell()
    Dim R As Range
    Dim W As Range
    Dim S As String
    On Error Resume Next
    xTitleId = "AddPrefixToCell"
    Set W = Application.Selection
    Set W = Application.InputBox("select a Range", xTitleId, W.Address, Type:=8)
    S = Application.InputBox("Add prefix character", xTitleId, "", Type:=2)
    For Each R In W
        R.Value = S & R.Value
    Next
End Sub

5# back to the current worksheet, then run the above excel macro. Click Run button.

add prefix or suffix5

6# select a range that you want to add prefix, click OK button, then add one prefix string or character. Click OK button.

add prefix or suffix6

add prefix or suffix7

7# you will see that the prefix is added to all range of cells.

add prefix or suffix8

If you want to add suffix to a range of cells with VBA macro in Excel, you can use the following VBA macro.

Sub AddSuffixToCell()
    Dim R As Range
    Dim W As Range
    Dim S As String
    On Error Resume Next
    xTitleId = "AddSuffixToCell"
    Set W = Application.Selection
    Set W = Application.InputBox("select a Range", xTitleId, W.Address, Type:=8)
    S = Application.InputBox("Add suffix character", xTitleId, "", Type:=2)
    For Each R In W
        R.Value = R.Value & S
    Next
End Sub

add prefix or suffix9


Related Functions

  • Excel Concat function
    The excel CONCAT function combines 2 or more strings or ranges together.This is a new function in Excel 2016 and it replaces the CONCATENATE function.The syntax of the CONCAT function is as below:=CONCAT (text1,[text2],…)…

 

Comments

So empty here ... leave a comment!

Leave a Reply

Your email address will not be published. Required fields are marked *

Sidebar