386

How can I construct the following string in an Excel formula:

Maurice "The Rocket" Richard

If I'm using single quotes, it's trivial: ="Maurice 'The Rocket' Richard" but what about double quotes?

13 Answers 13

566

Have you tried escaping with an additional double-quote? By escaping a character, you are telling Excel to treat the " character as literal text.

= "Maurice ""The Rocket"" Richard"
Sign up to request clarification or add additional context in comments.

Comments

194

Alternatively, you can use the CHAR function:

= "Maurice " & CHAR(34) & "Rocket" & CHAR(34) & " Richard"

5 Comments

This works more consistently for me than "" Maybe it's just because I have Mac Excel 2011
@Ivanoats: Nope, it's not a Mac thing (using Windows here) - this does work more consistently; in my case, concatenating using & with a double quote just before or just after the ampersand didn't work using the double-double-quote method.
Works more consistently for me, as I often need to wrap quotation marks around a complicated string built up of multiple concatenated fields with interspersed punctuation. In my most recent case, to come up with something like this: "NameOfLocation, Street Address, City, State Zip"
This works 100% of the time. I tried "" before but it gave me error for ""-"". Using CHAR(34),"-",CHAR(34) works.
This is the answer. BUT ALSO - I could not copy the cell and paste it into VSCode, I had to paste values into another cell and then copy that cell and paste it into VSCode. 2 Microsoft products working well. Bad +Bad = "BAD"
27

Three double quotes: " " " x " " " = "x" Excel will auto change to one double quote. e.g.:

=CONCATENATE("""x"""," hi")  

= "x" hi

4 Comments

If this would be true, then please elaborate on the outcome of =concatenate("a"""b"). According to your observation, the outcome would be a"b. This is not the case. In fact this expression will not even be accepted by Excel.
you forgot the comma
The outer quotes in your example are just starting and ending the string. "" creates a quote character, not """.
Two double-quotes will auto change to one double-quote: =CONCATENATE("<""x"">"," hi") -> <"x"> hi
8

In the event that you need to do this with JSON:

=CONCATENATE("'{""service"": { ""field"": "&A2&"}}'")

3 Comments

Thank you! This totally helped me! I was struggling to properly format a JSON array in my cells.
Why call CONCATENATE with 1 argument?
@infinitezero In this case, the single argument contains dynamic concatenation (&), and Excel resolves it correctly, making it a convenient way to construct complex strings in a single step.
7

I use a function for this (if the workbook already has VBA).

Function Quote(inputText As String) As String
  Quote = Chr(34) & inputText & Chr(34)
End Function

This is from Sue Mosher's book "Microsoft Outlook Programming". Then your formula would be:

="Maurice "&Quote("Rocket")&" Richard"

This is similar to what Dave DuPlantis posted.

Comments

5

Use chr(34) Code:

    Joe = "Hi there, " & Chr(34) & "Joe" & Chr(34)
    ActiveCell.Value = Joe

Result:

    Hi there, "joe"

Comments

3

Concatenate " as a ceparate cell:

    A |   B   | C | D
1   " | text  | " | =CONCATENATE(A1; B1; C1);

D1 displays "text"

Comments

1

will this work for macros using .Formula = "=THEFORMULAFUNCTION("STUFF")" so it would be like: will this work for macros using .Formula = "=THEFORMULAFUNCTION(CHAR(34) & STUFF & CHAR(34))"

2 Comments

Don't know if this particular syntax is available in VBA. Give it a try.
1

Returning an empty or zero-length string (e.g. "") to make a cell appear blank is a common practise in a worksheet formula but recreating that option when inserting the formula through the Range.Formula or Range.FormulaR1C1 property in VBA is unwieldy due to the necessity of having to double-up the double-quote characters within a quoted string.

The worksheet's native TEXT function can produce the same result without using quotes.

'formula to insert into C1 - =IF(A1<>"", B1, "")
range("C1").formula = "=IF(A1<>"""", B1, """")"         '<~quote chars doubled up
range("C1").formula = "=IF(A1<>TEXT(,), B1, TEXT(,))"   '<~with TEXT(,) instead

To my eye, using TEXT(,) in place of "" cleans up even a simple formula like the one above. The benefits become increasingly significant when used in more complicated formulas like the practise of appending an empty string to a VLOOKUP to avoid returning a zero to the cell when a lookup results in a blank or returning an empty string on no-match with IFERROR.

'formula to insert into D1 - =IFERROR(VLOOKUP(A1, B:C, 2, FALSE)&"", "")
range("D1").formula = "=IFERROR(VLOOKUP(A1, B:C, 2, FALSE)&"""", """")"
range("D1").formula = "=IFERROR(VLOOKUP(A1, B:C, 2, FALSE)&TEXT(,), TEXT(,))"

With TEXT(,) replacing the old "" method of delivering an empty string, you might get to stop using an abacus to determine whether you have the right number of quote characters in a formula string.

Comments

0

VBA Function

1) .Formula = "=""THEFORMULAFUNCTION ""&(CHAR(34) & ""STUFF"" & CHAR(34))"

2) .Formula = "THEFORMULAFUNCTION ""STUFF"""

The first method uses vba to write a formula in a cell which results in the calculated value:

 THEFORMULAFUNCTION "STUFF"

The second method uses vba to write a string in a cell which results in the value:

 THEFORMULAFUNCTION "STUFF"

Excel Result/Formula

1) ="THEFORMULAFUNCTION "&(CHAR(34) & "STUFF" & CHAR(34))

2) THEFORMULAFUNCTION "STUFF"

Comments

0
="Maurice "&"""TheRocker"""&" Richard"

Comments

-1

The following formula works on Excel as well as Numbers (on MAC) :

= "Maurice " & """" & "The Rocket" & """" & " Richard"

Use & """" & to get a single double quote surrounding your string.

2 Comments

This is no different to the accepted answer, and add no additional value
While not actually asked in the question, is when concatenating fields for SQL or other similar things it's useful. I recently needed to turn a set of phone numbers (like +16735552929) into a numeric with a leading zero to match contact numbers in a database. After stripping the + and country code, I had to add a leading zero, speech marks, and a comma. The formula was like this: =C2&",""""&B3&""""" And it requires four " (instead of three) to add a speech mark. It's easier than using and remembering CHAR(34).
-2

There is another way, though more for " How can I construct the following string in an Excel formula: "Maurice "The Rocket" Richard" " than " How to create strings containing double quotes in Excel formulas? ", which is simply to use two single quotes:

SO216616 example

On the left is Calibri snipped from an Excel worksheet and on the right a snip from a VBA window. In my view escaping as mentioned by @YonahW wins 'hands down' but two single quotes is no more typing than two doubles and the difference is reasonably apparent in VBA without additional keystrokes while, potentially, not noticeable in a spreadsheet.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.