Insert formula in text box google sheets

This tutorial will teach you how to add text in Google Sheets at the same position of all cells at once: at the beginning, at the end, after the N-th character, before or after particular characters.

As it happens, there's no direct standard way to insert text strings and characters to a certain position of a Google Sheets cell, not to mention to all selected cells at once. But here it goes — several workarounds to add text to the desired positions. They include some standard functions and a special Add text add-on.

Formulas to add text in Google Sheets

Though formulas in spreadsheets require a bit of learning, they can solve lots of different tasks. Inserting text in Google Sheets cells is not an exception.

Insert text at the beginning of Google Sheets cells

Concatenation in spreadsheets is usually used to combine two records into one string, e.g. 'Solar' from A1 and 'Opposites' from B1 will become 'Solar Opposites' in C1.

But how is it supposed to help when you need to add the new text to Google Sheets cells that already contain some data? Pretty easy: concatenate the 'new' part with the 'old' part.

How to add text in Google Sheets cells using an ampersand (&)

Ampersand is a special concatenation character that is used to merge values in spreadsheets. When you use it in cells, it looks like this:

="John "&"Doe"

or

=A2&B2

The result will be literally 'John Doe' or any other combo of whatever lies in A2 and B2.

I'm going to take advantage of this to insert new text at the beginning and the end of my cells.

Let's suppose I have a list of phone numbers belonging to customers in the US:


I'm going to use the ampersand to insert a country code — +1 — at the beginning of those cells. Since records will look like formulas, I will do that in the neighbouring column. Here's what I enter to B2:

="+1 "&A2

Note. I enter space after +1 in the same double-quotes since the formula doesn't separate records by default.

I could copy that formula down the column to fill other cells, but I have a better idea. I will wrap the formula in B2 in ArrayFormula and change the A2 reference to the range for the entire column:

=ArrayFormula("+1 "&A2:A7)

Add text at the beginning with the CONCATENATE function

The CONCATENATE function also exists in spreadsheets so you could merge text strings. But unlike the ampersand, the function makes you list the units to merge as its arguments:

CONCATENATE(string1, [string2, ...])

Tip. If you want to learn the function inside out, we have an entire blog post devoted to it.

And that's what I'm going to do: use the new text that I want to add as one of those arguments. Look how I use the function to add the same country codes to the beginning of the phone numbers:

=CONCATENATE("+1"," ",A2)

Tip. I mention space as an individual argument — the second one in my case.

Then you just copy the formula down the column if Google Sheets doesn't offer to auto-fill it for you and you will have that country code added at the beginning of all cells:

Insert text at the end of Google Sheets cells

To add text in Google Sheets at the end of cells, you can use the same concatenation methods as for inserting text at the beginning of cells — an ampersand (&) and the CONCATENATE function.

Use ampersand to add text in Google Sheets

Let's see how the ampersand is used to add text or any characters to the end of the cells.

This time, you need to place a reference to a cell with the existing record first, then append the new text:

=A2&", US"


To insert the same to all other cells, ArrayFormula will also help:

Tip. Of course, you can add the text at both positions in all cells at the same time:

=ArrayFormula("+1 "&A2:A7&", US")

How the CONCATENATE function adds text to the end of cells

The CONCATENATE function inserts text to the end of Google Sheets cells just like it does to the beginning. Only this time mention your new text string as the last argument:

=CONCATENATE(A2,", ","US")

How to add text in Google Sheets before/after characters

REGEXREPLACE is a Google Sheets function that replaces a part of the text in a cell with some other text.

The name of the function is actually an acronym from 'regular expression replace'. That's right — the function uses regular expressions to look for a certain text in a certain position and replace it with the required string.

I'll show you how to use that to your advantage and replace one string with the other while inserting new characters at the same time.

Tip. If regular expressions are the last thing you want to spend your time on, I have good news. Below I describe one user-friendly tool that will add text almost in an instant. Feel free to jump to it right away.

REGEXREPLACE needs 3 arguments:

REGEXREPLACE(text, regular_expression, replacement)

  • text — a text (or a reference to a cell with the text) that you want to change.
  • regular_expression — a combination of characters that represents a search pattern. You'll be looking for all strings that match this pattern.
  • replacement — a string to insert instead of text.

It's the 2nd argument that requires the most attention and a learning curve. Let's see.

I have the same list of randomly generated US phone numbers:


I'm going to make these numbers look presentable by wrapping the country code into brackets and adding a couple of whitespaces: +1 (202) 5550158.

Here's the formula I should use:

=REGEXREPLACE(A2,"(.*)202(.*)","$1 (202) $2")


Let me break it down into pieces for you:

  • A2 is a cell where I want to make the changes — this one is easy :)
  • "(.*)202(.*)" is my search mask. Let's dig deeper into this one.

    First of all, everything you enter here must always be enclosed in double-quotes.

    Then I tell the function to find the code — 202 — no matter what stands before or after it — (.*)

    A period and an asterisk in brackets is my regular expression: period stands for any character, asterisk — for any number of such characters, and brackets are required to group those characters.

    Note. There are lots and lots of regular expressions that will help you locate the text in various positions in cells. Many people use them daily, hence, there are special pages on the correct syntax of these regular expressions.

  • "$1 (202) $2" is what I want to get instead.

    As you can see, I've already added brackets around 202. That is my main goal.

    $1 and $2 stand for those 2 groups of characters — (.*) — that I mentioned in the previous argument. This is required so that the formula could return everything before and after 202 from that cell intact.

Phew!

Don't worry if it still looks difficult — this is not the easiest thing to understand. Feel free to jump to the last and the easiest solution right away or bear with me for I'm going to insert those dashes in-between numbers.

Add text in Google Sheets after the N-th character

I will go ahead and add a dash after 555: +1 (202) 555-0158. If you count the characters, you will see that the dash is going to be inserted at the same position in all the cells — after the 12th character.

So for this example, I will show you the mask required to add text after the N-th character in a cell:

=REGEXREPLACE(B2,"(.{12})(.*)","$1-$2")

  • This time, a cell I'm changing is B2.
  • What does "(.{12})(.*)" mean?

    I want to count characters starting from the left and stop on the 12th one — (.{12}) This is my first group, and I will insert my extra character right after. Then follows the second group — all remaining characters — (.*)

    Tip. Don't forget to wrap everything in double-quotes.

  • "$1-$2" — is how I add that extra dash.

    I mention the first group without changes here — $1. Then insert my character (-) and mention the second group to append it intact — $2.

And this is it :) Of course, your use case may be different and may require another mask. Feel free to refer to this list of masks and their correct syntax.

Or, instead, give the next solution a try — no formulas, no masks. Just a simple add-on with 5 radio buttons to solve the task.

Formula-free way to add text in Google Sheets

There's a more elegant, quicker and user-friendly solution available to insert text in Google Sheets to any part of your cells. The add-on is called Add text and is part of the Power Tools collection.

Tip. Watch this video to get to know the tool better, ot feel free to read the short introduction right below it.

With this add-on, you are 4 steps away from the result:

  1. Select the cells to handle.
  2. Enter the text you want to add.
  3. Choose one of 5 positions where you'd like to insert your string.
  4. Click Run.


You can even skip empty cells and add text only to cells with data.

Power Tools also includes 30 more add-ons for spreadsheets, so it's definitely worth checking out.

I hope that by now you know more about adding text in Google Sheets at different positions of cells. If you have any questions left, I'll be waiting for them in the comments section below :) See you in the next blog post!

You may also be interested in:

Can you put text and a formula in the same cell in Google Sheets?

Using the CONCATENATE Function to Combine Formula and Text The only difference is in the way both are used. The general syntax for the CONCATENATE Google Sheets text and formula in same cell function is: =CONCATENATE(text1, [text2],…) Where text1, text2, etc.

How do I reference a cell in a text box in Google Sheets?

Click the cell, go to the Formula Bar, and select a specific part of text in the cell by dragging your cursor through it. Enter, paste, or choose the link location in the Link box. Again, this can be another cell, sheet, webpage, or custom URL. Click Apply.

How do you add a formula in a cell with Google Sheets?

Use a formula.
Open a spreadsheet..
Type an equal sign (=) in a cell and type in the function you want to use. ... .
A function help box will be visible throughout the editing process to provide you with a definition of the function and its syntax, as well as an example for reference..

How do I use text formulas in Google Sheets?

How Do I Use the TEXT Formula in Google Sheets? The TEXT formula is =TEXT(num, format), where num represents the number or the cell address containing the number which needs to be converted into text. The format represents the method by which you want to display the data.

Postingan terbaru

LIHAT SEMUA