Jon C
Jon C

Reputation: 37

Excel copy contents from multiple cells adding quotations

I'm trying to combine contents from multiple cells in excel. Here is an example of what i'm wanting to do:

(Cell1): John Doe

(Cell2): 5950

(Cell3): Autofill with "John Doe" XXXXXX5950

I know i can combine the cells using the formula =&[Cell1]&" XXXXXX"&[Cell2]

But I want it to put the " " on each side of the name, but the code won't except it since part of using the formula is using the " symbol. Any help on this?

Upvotes: 0

Views: 40

Answers (2)

Scott Holtzman
Scott Holtzman

Reputation: 27259

You can escape the " character in VBA by using double quotes.

Range("A1").Formula = """" & Range("B1").Value & """ XXXXXX" & Range("C1").Value

Or you can also use ASCII character 34 as well.

Range("A1").Formula = Chr(34) & Range("B1").Value & Chr(34) & " XXXXX" & Range("C2").Value

Upvotes: 1

Magnetron
Magnetron

Reputation: 8573

Use two double-quotes inside a string to put a double-quote:

=""""&[Cell1]&""" XXXXXX"&[Cell2]

Upvotes: 1

Related Questions