Insert text to excel cell

This post will guide you how to insert character or text in middle of cells in Excel. How do I add text string or character to each cell of a column or range with a formula in Excel. How to add text to the beginning of all selected cells in Excel. How to add character after the first character of cells in Excel.

Assuming that you have a list of data in range B1:B5 that contain string values and you want to add one character “E” after the first character of string in Cells. You can refer to the following two methods.

Table of Contents

  • 1. Insert Character or Text to Cells with a Formula
  • 2. Insert Character or Text to Cells with VBA
  • 3. Video: Insert Character or Text to Cells
  • 4. Related Functions

1. Insert Character or Text to Cells with a Formula

To insert the character to cells in Excel, you can use a formula based on the LEFT function and the MID function. Like this:

=LEFT(B1,1) & "E" & MID(B1,2,299)

Type this formula into a blank cell, such as: Cell C1, and press Enter key. And then drag the AutoFill Handle down to other cells to apply this formula.

insert text to cells1

This formula will inert the character “E” after the first character of string in Cells. And if you want to insert the character or text string after the second or third or N position of the string in Cells, you just need to replace the number 1 in Left function and the number 2 in MID function as 2 and 3. Like below:

=LEFT(B1,2) & "E" & MID(B1,3,299)

insert text to cells2

You can also use an Excel VBA Macro to insert one character or text after the first position of the text string in Cells. Just do the following steps:

Step1: open your excel workbook and then click on “Visual Basic” command under DEVELOPER Tab, or just press “ALT+F11” shortcut.

Get the position of the nth using excel vba1

Step2: then the “Visual Basic Editor” window will appear.

Step3: click “Insert” ->”Module” to create a new module.

convert column number to letter3

Step4: paste the below VBA code into the code window. Then clicking “Save” button.

insert text to cells3

Sub AddCharToCells()
    Dim cel As Range
    Dim curR As Range
    Set curR = Application.Selection
    Set curR = Application.InputBox("select one Range that you want to insert one 
    character", "add character to cells", curR.Address, Type: = 8)
    For Each cel In curR
        cel.Value = VBA.Left(cel.Value, 1) & "E" & VBA.Mid(cel.Value, 2, 
        VBA.Len(cel.Value) - 1)
    Next
End Sub

Step5: back to the current worksheet, then run the above excel macro. Click Run button.

insert text to cells4

Step6: select one Range that you want to insert one character.
insert text to cells5

Step7: lets see the result.

insert text to cells6

3. Video: Insert Character or Text to Cells

This video will demonstrate how to insert character or text in middle of cells in Excel using both formulas and VBA code.

  • Excel MID function
    The Excel MID function returns a substring from a text string at the position that you specify.The syntax of the MID function is as below:= MID (text, start_num, num_chars)…
  • Excel LEFT function
    The Excel LEFT function returns a substring (a specified number of the characters) from a text string, starting from the leftmost character.The LEFT function is a build-in function in Microsoft Excel and it is categorized as a Text Function.The syntax of the LEFT function is as below:= LEFT(text,[num_chars])…

Содержание

  1. Add text strings at the beginning, at the end, or at another position in Excel cells
  2. Before you begin, add Add Characters to Excel
  3. How to add characters at the beginning of cells
  4. How to add characters at the end of cells
  5. How to add characters in the middle of cells
  6. How to add characters before or after specific text in cells
  7. Set options for adding characters to cells
  8. How to add text or character to every cell in Excel
  9. Excel formulas to add text/character to cell
  10. Concatenation operator
  11. CONCATENATE function
  12. CONCAT function
  13. How to add text to the beginning of cells
  14. How to add text to the end of cells in Excel
  15. Add characters to beginning and end of a string
  16. Combine text from two or more cells
  17. How to add special character to cell in Excel
  18. How to add text to formula in Excel
  19. How to insert text after Nth character
  20. How to add text before/after a specific character
  21. Add text after specific character
  22. Insert text before specific character
  23. How to add space between text in Excel cell
  24. How to add the same text to existing cells with VBA
  25. Prepend text to beginning
  26. Append text to end
  27. Add text or character to multiple cells with Ultimate Suite

Add text strings at the beginning, at the end, or at another position in Excel cells

When you need to insert some text into each Excel cell, creating functions or using VBA can be quite time consuming. It gets even more complicated if you need, for example, to add text into a specific position in a cell or before specific text.

The Add Characters feature helps add custom substrings (letters, numbers, spaces, commas or any other characters) to cells in seconds:

Before you begin, add Add Characters to Excel

Add Characters is one of the 20+ features within XLTools Add-in for Excel. Works in Excel 2019, 2016, 2013, 2010, desktop Office 365.

How to add characters at the beginning of cells

Click the Data Cleaning button on XLTools ribbon Select Add characters from the drop-down list A dialogue box will open.

Select the range where you want to add characters.

Type the substring you want to add to each cell.

Choose the position in a cell: at the beginning .

Click OK Done, the text string is added at the beginning of each cell.

How to add characters at the end of cells

Click the Data Cleaning button on XLTools ribbon Select Add characters from the drop-down list A dialogue box will open.

Select the range where you want to add characters.

Type the substring you want to add to each cell.

Choose the position in a cell: at the end .

Click OK Done, the text string is added at the end of each cell.

How to add characters in the middle of cells

Click the Data Cleaning button on XLTools ribbon Select Add characters from the drop-down list A dialogue box will open.

Select the range where you want to add characters.

Type the substring you want to add to each cell.

Choose the position in a cell: after character number N Specify the number of characters from the beginning, where you want to insert the text string.

Click OK Done, the text string is added in the middle of each cell.

How to add characters before or after specific text in cells

Click the Data Cleaning button on XLTools ribbon Select Add characters from the drop-down list A dialogue box will open.

Select the range where you want to add characters.

Type the substring you want to add to each cell.

Choose the position in a cell: before this tex t or after this text Type the text string to search for (case sensitive by default).

Click OK Done, the text string is added before or after the specified text in those cells, where it was found.

Set options for adding characters to cells

By default, the Add Characters feature does not process cells that contain formulas, not to interfere with calculations. You can specify additional data processing options:

Check the Skip empty cells option

Select this option, if you don’t want to add the characters into empty (blank) cells.

Check the Skip non-text cells option

Select this option, if you want to process only cells with text. All cells that have number, date, currency or other format will be ignored.

Check the Skip header row option

Select this option, if you want to ignore the first row with the table header.

Источник

How to add text or character to every cell in Excel

by Svetlana Cheusheva, updated on March 10, 2023

Wondering how to add text to an existing cell in Excel? In this article, you will learn a few really simple ways to insert characters in any position in a cell.

When working with text data in Excel, you may sometimes need to add the same text to existing cells to make things clearer. For example, you might want to put some prefix at the beginning of each cell, insert a special symbol at the end, or place certain text before a formula.

I guess everyone knows how to do this manually. This tutorial will teach you how to quickly add strings to multiple cells using formulas and automate the work with VBA or a special Add Text tool.

Excel formulas to add text/character to cell

To add a specific character or text to an Excel cell, simply concatenate a string and a cell reference by using one of the following methods.

Concatenation operator

The easiest way to add a text string to a cell is to use an ampersand character (&), which is the concatenation operator in Excel.

This works in all versions of Excel 2007 — Excel 365.

CONCATENATE function

The same result can be achieved with the help of the CONCATENATE function:

The function is available in Excel for Microsoft 365, Excel 2019 — 2007.

CONCAT function

To add text to cells in Excel 365, Excel 2019, and Excel Online, you can use the CONCAT function, which is a modern replacement of CONCATENATE:

Note. Please pay attention that, in all formulas, text should be enclosed in quotation marks.

These are the general approaches, and the below examples show how to apply them in practice.

How to add text to the beginning of cells

To add certain text or character to the beginning of a cell, here’s what you need to do:

  1. In the cell where you want to output the result, type the equals sign (=).
  2. Type the desired text inside the quotation marks.
  3. Type an ampersand symbol (&).
  4. Select the cell to which the text shall be added, and press Enter .

Alternatively, you can supply your text string and cell reference as input parameters to the CONCATENATE or CONCAT function.

For example, to prepend the text «Project:» to a project name in A2, any of the below formulas will work.

In all Excel versions:

In Excel 365 and Excel 2019:

Enter the formula in B2, drag it down the column, and you will have the same text inserted in all cells.

Tip. The above formulas join two strings without spaces. To separate values with a whitespace, type a space character at the end of the prepended text (e.g. «Project: «).

For convenience, you can input the target text in a predefined cell (E2) and add two text cells together:

Please notice that the address of the cell containing the prepended text is locked with the $ sign, so that it won’t shift when copying the formula down.

With this approach, you can easily change the added text in one place, without having to update every formula.

How to add text to the end of cells in Excel

To append text or specific character to an existing cell, make use of the concatenation method again. The difference is in the order of the concatenated values: a cell reference is followed by a text string.

For instance, to add the string «-US» to the end of cell A2, these are the formulas to use:

Alternatively, you can enter the text in some cell, and then join two cells with text together:

Please remember to use an absolute reference for the appended text ($D$2) for the formula to copy correctly across the column.

Add characters to beginning and end of a string

Knowing how to prepend and append text to an existing cell, there is nothing that would prevent you from using both techniques within one formula.

As an example, let’s add the string «Project:» to the beginning and «-US» to the end of the existing text in A2.

=CONCATENATE(«Project:», A2, «-US»)

=CONCAT(«Project:», A2, «-US»)

With the strings input in separate cells, this works equally well:

Combine text from two or more cells

To place values from multiple cells into one cell, concatenate the original cells by using the already familiar techniques: an ampersand symbol, CONCATENATE or CONCAT function.

For example, to combine values from columns A and B using a comma and a space («, «) for the delimiter, enter one of the below formulas in B2, and then drag it down the column.

Add text from two cells with an ampersand:

Combine text from two cells with CONCAT or CONCATENATE:

When adding text from two columns, be sure to use relative cell references (like A2), so they adjust correctly for each row where the formula is copied.

To combine text from multiple cells in Excel 365 and Excel 2019, you can leverage the TEXTJOIN function. Its syntax provides for a delimiter (the first argument), which makes the formular more compact and easier to manage.

For example, to add strings from three columns (A, B and C), separating the values with a comma and a space, the formula is:

=TEXTJOIN(«, «, TRUE, A2, B2, C2)

How to add special character to cell in Excel

To insert a special character in an Excel cell, you need to know its code in the ASCII system. Once the code is established, supply it to the CHAR function to return a corresponding character. The CHAR function accepts any number from 1 to 255. A list of printable character codes (values from 32 to 255) can be found here.

To add a special character to an existing value or a formula result, you can apply any concatenation method that you like best.

For example, to add the trademark symbol (в„ў) to text in A2, any of the following formulas will work:

How to add text to formula in Excel

To add a certain character or text to a formula result, just concatenate a string with the formula itself.

Let’s say, you are using this formula to return the current time:

=TEXT(NOW(), «h:mm AM/PM»)

To explain to your users what time that is, you can place some text before and/or after the formula.

Insert text before formula:

=»Current time: «&TEXT(NOW(), «h:mm AM/PM»)

=CONCATENATE(«Current time: «, TEXT(NOW(), «h:mm AM/PM»))

=CONCAT(«Current time: «, TEXT(NOW(), «h:mm AM/PM»))

Add text after formula:

=TEXT(NOW(), «h:mm AM/PM»)&» — current time»

=CONCATENATE(TEXT(NOW(), «h:mm AM/PM»), » — current time»)

=CONCAT(TEXT(NOW(), «h:mm AM/PM»), » — current time»)

Add text to formula on both sides:

=»It’s » &TEXT(NOW(), «h:mm AM/PM»)& » here in Gomel»

=CONCATENATE(«It’s «, TEXT(NOW(), «h:mm AM/PM»), » here in Gomel»)

=CONCAT(«It’s «, TEXT(NOW(), «h:mm AM/PM»), » here in Gomel»)

How to insert text after Nth character

To add a certain text or character at a certain position in a cell, you need to split the original string into two parts and place the text in between. Here’s how:

  1. Extract a substring preceding the inserted text with the help of the LEFT function:
    LEFT(cell, n)
  2. Extract a substring following the text using the combination of RIGHT and LEN:
    RIGHT(cell, LEN(cell) -n)
  3. Concatenate the two substrings and the text/character using an ampersand symbol.

The complete formula takes this form:

The same parts can be joined together by using the CONCATENATE or CONCAT function:

The task can also be accomplished by using the REPLACE function:

The trick is that the num_chars argument that defines how many characters to replace is set to 0, so the formula actually inserts text at the specified position in a cell without replacing anything. The position (start_num argument) is calculated using this expression: n+1. We add 1 to the position of the nth character because the text should be inserted after it.

For example, to insert a hyphen (-) after the 2 nd character in A2, the formula in B2 is:

=LEFT(A2, 2) &»-«& RIGHT(A2, LEN(A2) -2)

=CONCATENATE(LEFT(A2, 2), «-«, RIGHT(A2, LEN(A2) -2))

Drag the formula down, and you will have the same character inserted in all the cells:

How to add text before/after a specific character

To insert certain text before or after a particular character, you need to determine the position of that character in a string. This can be done with the help of the SEARCH function:

Once the position is determined, you can add a string exactly at that place by using the approaches discussed in the above example.

Add text after specific character

To insert some text after a given character, the generic formula is:

For instance, to insert the text (US) after a hyphen in A2, the formula is:

=LEFT(A2, SEARCH(«-«, A2)) &»(US)»& RIGHT(A2, LEN(A2) — SEARCH(«-«, A2))

=CONCATENATE(LEFT(A2, SEARCH(«-«, A2)), «(US)», RIGHT(A2, LEN(A2) -SEARCH(«-«, A2)))

Insert text before specific character

To add some text before a certain character, the formula is:

As you see, the formulas are very similar to those that insert text after a character. The difference is that we subtract 1 from the result of the first SEARCH to force the LEFT function to leave out the character after which the text is added. To the result of the second SEARCH, we add 1, so that the RIGHT function will fetch that character.

For example, to place the text (US) before a hyphen in A2, this is the formula to use:

=LEFT(A2, SEARCH(«-«, A2) -1) &»(US)»& RIGHT(A2, LEN(A2) -SEARCH(«-«, A2) +1)

=CONCATENATE(LEFT(A2, SEARCH(«-«, A2) -1), «(US)», RIGHT(A2, LEN(A2) -SEARCH(«-«, A2) +1))

  • If the original cell contains multiple occurrences of a character, the text will be inserted before/after the first occurrence.
  • The SEARCH function is case-insensitive and cannot distinguish lowercase and uppercase characters. If you aim to add text before/after a lowercase or uppercase letter, then use the case-sensitive FIND function to locate that letter.

How to add space between text in Excel cell

In fact, it is just a specific case of the two previous examples.

To add space at the same position in all cells, use the formula to insert text after nth character, where text is the space character (» «).

For example, to insert a space after the 10 th character in cells A2:A7, enter the below formula in B2 and drag it through B7:

=LEFT(A2, 10) &» «& RIGHT(A2, LEN(A2) -10)

=CONCATENATE(LEFT(A2, 10), » «, RIGHT(A2, LEN(A2) -10))

In all the original cells, the 10 th character is a colon (:), so a space is inserted exactly where we need it:

To insert space at a different position in each cell, adjust the formula that adds text before/after a specific character.

In the sample table below, a colon (:) is positioned after the project number, which may contain a variable number of characters. As we wish to add a space after the colon, we locate its position using the SEARCH function:

=LEFT(A2, SEARCH(«:», A2)) &» «& RIGHT(A2, LEN(A2)-SEARCH(«:», A2))

=CONCATENATE(LEFT(A2, SEARCH(«:», A2)), » «, RIGHT(A2, LEN(A2)-SEARCH(«:», A2)))

How to add the same text to existing cells with VBA

If you often need to insert the same text in multiple cells, you can automate the task with VBA.

Prepend text to beginning

The below macros add text or a specific character to the beginning of all selected cells. Both codes rely on the same logic: check each cell in the selected range and if the cell is not empty, prepend the specified text. The difference is where the result is placed: the first code makes changes to the original data while the second one places the results in a column to the right of the selected range.

If you have little experience with VBA, this step-by-step guide will walk you through the process: How to insert and run VBA code in Excel.

Macro 1: adds text to the original cells

This code inserts the substring «PR-» to the left of an existing text. Before using the code in your worksheet, be sure to replace our sample text with the one you really need.

Macro 2: places the results in the adjacent column

Before running this macro, make sure there is an empty column to the right of the selected range, otherwise the existing data will be overwritten.

Append text to end

If you are looking to add a specific string/character to the end of all selected cells, these codes will help you get the work done quickly.

Macro 1: appends text to the original cells

Our sample code inserts the substring «-PR» to the right of an existing text. Naturally, you can change it to whatever text/character you need.

Macro 2: places the results in another column

This code places the results in a neighboring column. So, before you run it, make certain you have at least one empty column to the right of the selected range, otherwise your existing data will be overwritten.

Add text or character to multiple cells with Ultimate Suite

In the first part of this tutorial, you’ve learned a handful of different formulas to add text to Excel cells. Now, let’s me show you how to accomplish the task with a few clicks 🙂

With Ultimate Suite installed in your Excel, here are the steps to follow:

  1. Select your source data.
  2. On the Ablebits tab, in the Text group, click Add.
  3. On the Add Text pane, type the character/text you wish to add to the selected cells, and specify where it should be inserted:
    • At the beginning
    • At the end
    • Before specific text/character
    • After specific text/character
    • After Nth character from the beginning or end
  4. Click the Add Text button. Done!

As an example, let’s insert the string «PR-» after the «-» character in cells A2:A7. For this, we configure the following settings:

A moment later, we get the desired result:

These are the best ways to add characters and text strings in Excel. I thank you for reading and hope to see you on our blog next week!

Источник

There may be instances where you need to add the same text to all cells in a column. You might need to add a particular title before names in a list, or a particular symbol at the end of the text in every cell.

The good thing is you don’t need to do this manually.

Excel provides some really simple ways in which you can add text to the beginning and/ or end of the text in a range of cells.

In this tutorial we will see 4 ways to do this:

  • Using the ampersand operator (&)
  • Using the CONCATENATE function
  • Using the Flash Fill feature
  • Using VBA

So let’s get started!

Method 1: Using the ampersand Operator

An ampersand (&) can be used to easily combine text strings in Excel. Let’s see how you use it to add text at the beginning or end or both in Excel.

Using the ampersand Operator to Add Text to the Beginning of all Cells

The ampersand (&) is an operator that is mainly used to join several text strings into one.

Here’s how you can use it to add text to the beginning of all cells in a range. Let us assume you have the following list of names and want to add the title “Prof.” before every name:

Guest list data

Below are the  steps to add  a text before a text string in Excel:

  1. Click on the first cell of the column where you want the converted names to appear (B2).
  2. Type equal sign (=), followed by the text “Prof. “, followed by an ampersand (&).
  3. Select the cell containing the first name (A2).
  4. Press the Return Key.
  5. You will notice that the title “Prof.” is added before the first name in the list.Using formula to add text before the names
  6. It’s now time to copy this formula to the rest of the cells in the column. Simply double click the fill handle (located at the bottom right of cell B2). Alternatively, you can drag down the fill handle to achieve the same effect.

That’s it, all your cells in column B should now contain the title “Prof.” preceding each name.

Result when text is added

Using the ampersand Operator to Add Text to the End of all Cells

Now let us see how to add some text to the end of every name in the dataset. Let us say you want to add the text “(MD)” at the end of every name. In that case, here are the steps you need to follow:

  1. Click on the first cell of the column where you want the converted names to appear (C2 in our case).
  2. Type equal sign (=)
  3. Select the cell containing the first name (B2 in our case).
  4. Next, insert an ampersand (&), followed by the text “ (MD)”.
  5. Press the Return Key.
  6. You will notice that the text “(MD).” added after the first name in the list.Fromula to add text at the end of the string
  7. It’s now time to copy this formula to the rest of the cells in the column. Simply double click the fill handle (located at the bottom right of cell C2). Alternatively, you can drag down the fill handle to achieve the same effect.

All your cells in column C should now contain the text “(MD”) at the end of each name.

Adding text before and after a text string

Method 2: Using the CONCATENATE Function

CONCATENATE is an Excel function that you can use to add text at the beginning and end of the text string.

Let’s see how to use CONCATENATE to do this.

Using CONCATENATE to Add Text to the Beginning of all Cells

The CONCATENATE() function provides the same functionality as the ampersand (&) operator. The only difference is in the way both are used.

The general syntax for the CONCATENATE function is:

=CONCATENATE(text1, [text2], …)

Where text1, text2, etc. are substrings that you want to combine together.

Let’s apply the CONCATENATE function to the same dataset as above:

  1. Click on the first cell of the column where you want the converted names to appear (B2).
  2. Type equal sign (=).
  3. Enter the function CONCATENATE, followed by an opening bracket (.
  4. Type the title “Prof. ” in double-quotes, followed by a comma (,).
  5. Select the cell containing the first name (A2)
  6. Place a closing bracket. In our example, your formula should now be: =CONCATENATE(“Prof. “,A2).
  7. Press the Return Key.
  8. You will notice that the title “Prof.” is added before the first name on the list.CONCATENATE function to add text before the string
  9. It’s now time to copy this formula to the rest of the cells in the column. Simply double click the fill handle (located at the bottom right of cell B2). Alternatively, you can drag down the fill handle to achieve the same effect.

That’s it, all your cells in column B should now contain the title “Prof.” preceding each name.

CONCATENATE formula result

Using CONCATENATE to Add Text to the End of all Cells

Now let us see how to add some text to the end of every name in the dataset. Let us say you want to add the text “(MD)” at the end of every name. In that case, here are the steps you need to follow:

  1. Click on the first cell of the column where you want the converted names to appear (C2 in our example).
  2. Type equal sign (=).
  3. Enter the function CONCATENATE, followed by an opening bracket (.
  4. Select the cell containing the first name (B2 in our example).
  5. Next, insert a comma, followed by the text “ (MD)”.
  6. Place a closing bracket. In our example, your formula should now be: =CONCATENATE(B2,” (MD)”).
  7. Press the Return Key.
  8. You will notice that the text “(MD).” added after the first name in the list.CONCATENATE function to add text after the string
  9. It’s now time to copy this formula to the rest of the cells in the column. Simply double click the fill handle (located at the bottom right of cell C2).

All your cells in column C should now contain the text “(MD”) at the end of each name.

CONCATENATE formula result end

Notice that since you’re using a formula, your column C depends on columns A and B. So if you make any changes to the original values in column A, they get reflected in column C.

If you decide to only retain the converted names and delete columns A and B, you will get an error, as shown below:

Issue when deleting rhe dependent columns

To make sure that this does not happen, it’s best to first convert the formula results to permanent values copying them and pasting them as values in the same column (Right-click and select Paste Options->Values from the Popup menu).

Convert formulas to values

Now you can go ahead and delete columns A and B if you need to.

Also read: How to Remove First Character in Excel?

Method 3: Using the Flash Fill Feature

Flash fill is a relatively new feature that looks at the pattern of what you are trying to achieve and then does it for all the cells in a column.

You can also use Flash fill to so text manipulation as we will see in the following examples.

Using Flash Fill to Add Text to the Beginning of all Cells

The Excel flash fill feature is like a magical button. It is available if you’re on any Excel version from 2013 onwards.

The feature takes advantage of Excel’s pattern recognition capabilities. It basically recognizes a pattern in your data and automatically fills in the other cells of the column with the same pattern for you.

Here’s how you can use Flash Fill to add text to the beginning of all cells in a column:

  1. Click on the first cell of the column where you want the converted names to appear (B2).
  2. Manually type in the text Prof. , followed by the first name of your list.Type the expected result
  3. Press the Return Key.
  4. Click on cell B2 again.
  5. Under the Data tab, click on the Flash Fill button (in the ‘Data Tools’ group). Alternatively, you can just press CTRL+E on your keyboard (Command+E if you’re on a Mac).Click on Flash Fill

This will copy the same pattern to the rest of the cells in the column… in a flash!

Flash fill result

Using Flash Fill to Add Text to the End of all Cells in a Column

If you want to add the text “ (MD)” to the end of the names, follow the same steps:

  1. Click on the first cell of the column where you want the converted names to appear (C2).
  2. Manually type in or copy the text from column B2 into C2.
  3. Add the text “(MD)” after that.Type manually by adding the required text at the end of the string
  4. Under the Data tab, click on the Flash Fill or press CTRL+E on your keyboard (Command+E if you’re on a Mac).

That’s all, you get every cell filled in with the same pattern!

Final result of flash fill

We especially like this method because it is simple, quick, and easy. Moreover, since it’s formula-free, the results do not depend on the original columns.

So they remain unchanged even if you delete rows A and B!

Result in case you delete all the other columns

Method 4: Using VBA Code

And of course, if you’re comfortable with VBA, you can also add text before or after a text string using it.

Using VBA to Add Text to the Beginning of all Cells in a Column

If coding with VBA does not intimidate you then this method can help get your work done quickly too.

Here’s the code we will be using to add the title “Prof. “ to the beginning of all cells in a range. You can select and copy it:

Sub add_text_to_beginning()
Dim rng As Range
Dim cell As Range
Set rng = Application.Selection
For Each cell In rng
cell.Offset(0, 1).Value = "Prof. " & cell.Value
Next cell
End Sub

Follow these steps to use the above code:

  1. From the Developer Menu Ribbon, select Visual Basic.
  2. Once your VBA window opens, Click Insert->Module. Now you can start coding. Type or copy-paste the above lines of code into the module window. Your code is now ready to run.
  3. Select the range of cells containing the text you want to convert. Make sure the column next to it is blank because this is where the code will display the results.
  4. Navigate to Developer->Macros-> add_text_to_beginning->Run.

You will now see the converted text next to your selected range of cells.

Flash fill result

Note: You can change the text in line 6 from “Prof. ” to whatever text you need to add to the beginning of all cells.

Using VBA to Add Text to the End of all Cells in a Column

Now, what if you want to add text to the end of all the cells, instead of the beginning? This only involves making a tweak to line 6 of the above code. So if you want to add the text “ (MD)” to the end of all cells, change line 6 to:

cell.Offset(0, 1).Value = cell.Value & “ (MD)”

So your full code should now be:

Sub add_text_to_end()
Dim rng As Range
Dim cell As Range
Set rng = Application.Selection
For Each cell In rng
cell.Offset(0, 1).Value = cell.Value & " (MD)"
Next cell
End Sub

Here’s the final result:

Final result of flash fill

You can now delete the first two columns if you need to. Do remember to keep a backup of your sheet, because the results of VBA code are usually irreversible.

Note: You can change the text in line 6 from “ (MD)” to whatever text you need to add to the end of all cells in the range.

In this tutorial, we showed you four ways in which you can add text to the beginning and/ or end of all cells in a range.

There are plenty of other methods that you can find online too, and all of them work just as well as the ones shown here.

You may feel free to choose whatever method suits you, your requirement, and your version of Excel. In the end, what matters is getting what you need to be done quickly and effectively.

Other Excel tutorials you may like:

  • How to Remove Text after a Specific Character in Excel
  • How to Reverse a Text String in Excel
  • How to Count How Many Times a Word Appears in Excel
  • How to Remove Commas in Excel (from Numbers or Text String)
  • How to Remove a Specific Character from a String in Excel
  • How to Change Uppercase to Lowercase in Excel
  • How to Separate Address in Excel?
  • How to Concatenate with Line Breaks in Excel?
  • How to Separate Names in Excel

I’ve been working with SQL and Excel Macros, but I don’t know how to add text to a cell.

I wish to add the text "01/01/13 00:00" to cell A1. I can’t just write it in the cell because the macro clears the contents of the sheet first and adds the information afterwards.

How do I do that in VBA?

Our Man in Bananas's user avatar

asked Dec 16, 2013 at 13:43

Phil's user avatar

2

Range("$A$1").Value = "'01/01/13 00:00" will do it.

Note the single quote; this will defeat automatic conversion to a number type. But is that what you really want? An alternative would be to format the cell to take a date-time value. Then drop the single quote from the string.

answered Dec 16, 2013 at 13:44

Bathsheba's user avatar

BathshebaBathsheba

231k33 gold badges359 silver badges477 bronze badges

3

You could do

[A1].Value = "'O1/01/13 00:00"

if you really mean to add it as text (note the apostrophe as the first character).

The [A1].Value is VBA shorthand for Range("A1").Value.

If you want to enter a date, you could instead do (edited order with thanks to @SiddharthRout):

[A1].NumberFormat = "mm/dd/yyyy hh:mm;@"
[A1].Value = DateValue("01/01/2013 00:00")

answered Dec 16, 2013 at 13:47

Floris's user avatar

FlorisFloris

45.7k6 gold badges70 silver badges122 bronze badges

7

You need to use Range and Value functions.
Range would be the cell where you want the text you want
Value would be the text that you want in that Cell

Range("A1").Value="whatever text"

Manos Nikolaidis's user avatar

answered Mar 7, 2016 at 10:21

Garry's user avatar

GarryGarry

611 silver badge1 bronze badge

You can also use the cell property.

Cells(1, 1).Value = "Hey, what's up?"

Make sure to use a . before Cells(1,1).Value as in .Cells(1,1).Value, if you are using it within With function. If you are selecting some sheet.

enamoria's user avatar

enamoria

8762 gold badges11 silver badges29 bronze badges

answered Dec 19, 2018 at 6:40

Neha Kalani's user avatar

You have a couple (or many) cells with text in it. Now, you want to insert more text to them. Either at the beginning, in the middle or at the end. Here is how to easily do that!

Method 1: The fastest way to bulk insert text

Because it is the fastest and most convenient way, we go with this method first.

Use Professor Excel Tools to easily insert text - and select from further options (subscript, superscript or the position of where to insert the text).

Use Professor Excel Tools to easily insert text – and select from further options (subscript, superscript or the position of where to insert the text).
  1. Select all the cell in which you want to insert text.
  2. Click on “Insert Text” on the Professor Excel ribbon.
  3. Type your text and select further options (for example, you can specify the position (add the text in the beginning of the existing text, at the end or at a character position). Also, choose if you want o insert it as normal text, subscript or superscript.
  4. Click on Insert.

Click here to learn more about Professor Excel Tools. Or click here to start the download.


Professor Excel Tools Box

This function is included in our Excel Add-In ‘Professor Excel Tools’

(No sign-up, download starts directly)


Method 2: Use a string formula to combine two text parts

The second method is based on formulas. You can combine two text strings with the & sign (actually, there are four different ways to concatenate text, but using the & sign is usually the fastest).

So, let’s see how it works:

Concatenate the two text parts with the & sign.

Concatenate the two text parts with the & sign.

In this example, you have existing in cells B2 to B5. You want to add the word “Cool.” to it. So, the formula in cell C2 is:

 =B2&" Cool."

Please note that I have added a space before the word cool (on purpose…). The reason is that between the previous full stops and the word cool should have a space.

You can now copy the new cell (range C2 to C5). Paste it using paste special on top of the existing cells as values if you want to fully replace the original text cells.

Method 3: Try a workaround to insert text with the Find & Replace function

Admittedly, this method is a little bit trial and error. If it works depends on your existing cells. The main idea is to replace text from the original cells with new text.

Let’s go back to our original example. You again want to add the word “Cool.” to your existing cells:

Insert text with the Find and Replace function.

Insert text with the Find and Replace function.

In this case, we are lucky that all existing cells end with a full stop. We can use this to replace it the following way:

  1. Select all original cells.
  2. Press Ctrl + H on the keyboard so that the Find and Replace window opens.
  3. As “Find what:”, enter “.”
  4. Because we still want to keep the full stop, we also use this in the “Replace with:” field: “. Cool.”
  5. Click on Replace All.

If the result is not as expected, you can simply undo the replace process (press Ctrl + Z on the keyboard).

Method 4: Bulk insert text with a VBA macro

If you feel comfortable to use a short VBA macro, you can copy and paste the following code into a new VBA module. Please refer to this article for help.

Replace the word ” Cool.” with your text to add at the end. Also, you can set a text to insert in the beginning. Then, place the cursor within these lines of code and press F5 on the keyboard.

Sub bulkInsertText()
    Dim textToInsertAtTheEnd As String, textToInsertAtTheBeginning As String
    
    'Replace "Cool" with your text to insert at the end
    textToInsertAtTheEnd = " Cool."
    textToInsertAtTheBeginning = ""
    
    For Each cell In Selection
        If cell.HasFormula = False Then
            cell.Value = textToInsertAtTheBeginning & cell.Value & textToInsertAtTheEnd
        End If
    Next
    
End Sub

Image by Gerd Altmann from Pixabay

Henrik Schiffner is a freelance business consultant and software developer. He lives and works in Hamburg, Germany. Besides being an Excel enthusiast he loves photography and sports.

How can I add @gmail.com or something similar to a column of usernames without having to type this into each cell? I am using Excel 2010. I have a list of several hundred usernames that need to have @gmail.com or something similar added to create a csv file for upload.

Lance Roberts's user avatar

asked Sep 13, 2011 at 3:08

Dot Walker's user avatar

Assuming your names are in column starting from A1, you can use the formula:

=A1&"@gmail.com"

answered Sep 13, 2011 at 3:14

Hand-E-Food's user avatar

Hand-E-FoodHand-E-Food

4,8911 gold badge18 silver badges38 bronze badges

4

If you need to change the value of the cells, I’d recommend Hand-E-Food’s solution. (If you need to keep it in one column, just Copy, then Paste Special > Values back to the original column.)

However, if you want it to simply display the suffix without actually altering the cells’ values, you can use a custom number format instead. In Excel 2007 or later, select Custom in Home > Number. In earlier versions, it’s Format > Cells > Number. Use @"@gmail.com" as the custom format.

In this screen shot, column A is using a custom format as I describe. Column B is using Hand’s solution (you can see the formula in the center right).

Excel custom formatting example

Community's user avatar

answered Sep 13, 2011 at 18:23

Ben Blank's user avatar

Ben BlankBen Blank

1,0342 gold badges13 silver badges21 bronze badges

Let’s say your usernames are in column A starting from A1. Go to B1, enter the following formula and drag it down till the end of the row where the list ends (or you can simply double click on the lower right corner of the cell).

=CONCATENATE(A1,"@gmail.com")

answered Sep 13, 2011 at 6:44

Mehper C. Palavuzlar's user avatar

A very easy way with notepad++:
If you need to make modification on a column, then:

  1. copy paste your excel colum on notepad++
  2. press alt + the arrows.
  3. what you will write will be add in all lines

Jens Erat's user avatar

Jens Erat

17.4k14 gold badges61 silver badges74 bronze badges

answered Jul 10, 2014 at 11:26

JinSnow's user avatar

JinSnowJinSnow

7049 silver badges23 bronze badges

If you want to add specified text in each cells of a selection directly, the following VBA macro will ease your work.

Step 1: Select the range in which you will add specified text;

Step 2: Hold down the Alt + F11 keys in Excel, and it opens the Microsoft Visual Basic for Applications window.

Step 3: Click Insert > Module, and paste the following VBA code in the Module Window.

Sub AppendToExistingOnRight()
Dim c as range
For each c in Selection
If c.value <> "" Then c.value = c.value & "@gmail.com" 
Next
End Sub

Step 4: Press the F5 key to run this macro.

Excellll's user avatar

Excellll

12.5k11 gold badges50 silver badges78 bronze badges

answered Mar 3, 2016 at 5:07

Piyush's user avatar

Like this post? Please share to your friends:
  • Insert text into word
  • Insert text in word document
  • Insert text in text box word
  • Insert text from word
  • Insert table of tables ms word