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.
Table of Contents
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.
If you want to add suffix to all cells with concatenation operator, you can use the following formula:
=A1&"excelhow"
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")
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.
2# then the “Visual Basic Editor” window will appear.
3# click “Insert” ->”Module” to create a new module
4# paste the below VBA code into the code window. Then clicking “Save” button.
Sub AddPrefixToCell() Set W = Application.Selection Set W = Application.InputBox("select one Range that you want to add prefix to each cell:", "AddPrefixToCell", W.Address, Type:=8) S = Application.InputBox("Please type a prefix character:", "AddPrefixToCell", "", 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.
6# select a range that you want to add prefix, click OK button, then add one prefix string or character. Click OK button.
7# you will see that the prefix is added to all range of cells.
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() Set W = Application.Selection Set W = Application.InputBox("select one Range that you want to add suffix to each cell:", "AddSuffixToCell", W.Address, Type:=8) S = Application.InputBox("Please type a prefix character:", "AddSuffixToCell", "", Type:=2) For Each R In W R.Value = R.Value & S Next End Sub
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],…)…
Leave a Reply
You must be logged in to post a comment.