Add an apostrophe at the beginning
If you want to add an apostrophe in Excel, you can do it using a simple formula. Place it into cell B2.
There is another, simple method. You can use the CHAR function instead of apostrophes. We need to pass a code that represents apostrophe. This code is 39.
Now, the formula is going to look like this.
You may want to consider using this one because it seems cleaner than the previous one. This method has a disadvantage that you must remember the code.
Both formulas are going to convert a value to a text. In our example, the cell with text stays text and the cell with a number is converted to text.
Leading and trailing apostrophes
Adding an apostrophe at the beginning is very similar to the previous example, and looks like this.
The CONCAT function
You can use the CONCAT function. It will join multiple strings into a single one.
Apostrophe at the beginning:
Apostrophe at the beginning and the end:
=CONCAT("'", A2, "'")
If you want, you can add apostrophes to the same column that contains values, instead of creating an additional one.
This formula does it.
Sub AddAnApostrophe() For Each cell In Selection cell.Value = "'" & cell.Value Next cell End Sub
This is how you can use this formula.
Select cells to which you want to add apostrophes and run the code.
Let’s modify the procedure, so it will add a visible apostrophe to the values.
Sub AddVisibleApostrophe() For Each cell In Selection cell.Value = "''" & cell.Value Next cell End Sub
This is the result.
In a similar way, you can modify the procedure to add apostrophes also at the end.
Sub AddAnApostrophe() For Each cell In Selection cell.Value = "''" & cell.Value & "'" Next cell End Sub
There is a tool in Excel, called Immediate Window. Many people don’t know about it, but it can be useful as you can write commands and execute them on the spot. Let’s use it in this example.
First, you have to open VBE by pressing Left Alt + F11 and then Ctrl + G to open the Immediate window.
Now, enter the following code and press Enter.
for each v in range("C1:C2") : v.value = "'" & v.value : next
This code works the same way as the first procedure AddAnApostrophe.