I have the following sample data,
I want to concatenate string1 and string2 to produce the concatenation result
"a" "b"
using the concatenate function
I did not find any the answer in official microsoft excel documentation
https://support.office.com/en-us/article/CONCATENATE-function-8f8ae884-2ca8-4f7a-b093-75d702bea31d
How would I do this in excel? Concatenate " quotation marks
I know it's not the prettiest solution but:
=CONCATENATE(CHAR(34) & A1 & CHAR(34), " " & CHAR(34) & B1 & CHAR(34))
or
=CONCATENATE(CHAR(34), A1, CHAR(34), " ", CHAR(34), B1, CHAR(34))
CHAR(34) can be used in place of ".
Edit:
If you prefer, CHAR(34) can be replaced with """", four double quote marks - for the same effect.
Related
I have a table in Excel that has 10 columns. For each row there are different numbers of cells populated e.g.
My concatenated string is as follows for HTML emails
(" + Machine1 + ", " + Machine2 + ", " + Machine3 + ", " + Machine4 + ", " + Machine5 + ", " + Machine6 + ")
However I want the comma to not show after the last cell in the row (whether that be column 3,4,5,6).
This is what I get
(TEST1, TEST2, TEST3 , TEST4, TEST5, , )
I want to remove the two commas at the end. Hope this makes sense!
If you have Office 365 Excel then use TEXTJOIN:
="(" & TEXTJOIN(", ",TRUE,A2:F2) & ")"
If not then you will need to use IF for each return and Mid:
=MID("(" & IF(A2 <> "",", " & A2,"") & IF(A2 <> "",", " & B2,"") & IF(C2 <> "",", " & C2,"") & IF(D2 <> "",", " & D2,"") & IF(E2 <> "",", " & E2,"") & IF(F2 <> "",", " & F2,""),3,999)
Alternative without IF
Just in addition to Scott's valid solution, I demonstrate an approach via the REPT function. Applied on a cell containing a string, it "repeats" its content & comma once (indicated by COUNTA() equalling 1), whereas an empty cell results in a zero repetition which allows to omit not only the cell content but the comma, too:
="(" & SUBSTITUTE(REPT(A1&",",COUNTA(A1))&REPT(B1&",",COUNTA(B1))&REPT(C1&",",COUNTA(C1))&REPT(D1&",",COUNTA(D1))&REPT(E1&",",COUNTA(E1))&REPT(F1&",",COUNTA(F1))&"$",",$",")")
A simple SUBSTITUTE removes the last comma, wherever it occurs before the closing bracket ")".
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?
Use two double-quotes inside a string to put a double-quote:
=""""&[Cell1]&""" XXXXXX"&[Cell2]
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
I am trying to string together text from cells across by row when some of the cells are blank. I also want to have commas separating the text from each cell but cannot figure out how to only have commas put in when there is data in a cell.
I have tried using variations of concatenate and stringing the text using A1&B1&C1 but nothing is returning the data in the format I want.
Is there a combination of nested formulas I can use that will return the data in the format I want?
Here's a VBA solution I had before the newer versions:
Public Function JOINCELLS(ByVal ref As Range) As String
Dim c As Range
For Each c In ref
If Len(c) > 0 Then
JOINCELLS = JOINCELLS & c & ", "
End If
Next
JOINCELLS = Left(JOINCELLS, Len(JOINCELLS) - 2)
End Function
Then, it's just =JOINCELLS(A1:D1).
The formula below could do the trick. Concatenate the val The trim would remove spaces from the ends, and the substitute would swap the space for the comma(space).
=SUBSTITUTE(TRIM(A1 & " " & B1 & " " & C1 & " " & D1), " ", ", ")
Edit from the comments below - you could update the spaces between the quotes to be any character that does not appear in your cells. You would just have to the substitute formula to match. If you don't use the | character for example:
=SUBSTITUTE(TRIM(A1 & "|" & B1 & "|" & C1 & "|" & D1), "|", ", ")
I currently have a spreadsheet with the following format
A1 = <Name>
B1 = <Email>
C1 = New-MailContact
D1 = '-Name
E1 = '-ExternalEmailAddress
F1 = =(C1&" "&D1&" ""&A1&"" "&E1&" ""&B1&""")
My issue is that my F1 column results in the following output:
New-MailContact -Name "&A1&" -ExternalEmailAddress "&B1&"
Can someone please help me to fix the A1 and B1 records so they show up as the actual name and email rather than A1 and B1?
You have a bunch of extra quotes
=C1 & " " & D1 & " " & A1 & " " & E1 & " " & B1
should display the data concatenated.
If you want the name or other fields to be quoted, for every quote you want add two quotes in the string:
= """" & C1 & """"
will display New-MailContact in quotes, like this "New-MailContact"
See this as " "" " where the outside quotes are to denote it as a string, and the two quotes inside are for displaying the one "
So if you need name and email (A1 and B1) quoted, you need
=C1 & " " & D1 & " """ & A1 & """ " & E1 & " """ & B1 & """"
More examples.
The ASCII code for a double-quote character is 22 hex or 34 dec. The ASCII character code for a space is 20 hex or 32 dec.
=C1&CHAR(32)&D1&CHAR(32)&CHAR(34)&A1&CHAR(34)&CHAR(32)&E1&CHAR(32)&CHAR(34)&B1&CHAR(34)
'alternate with CONCATENATE
=CONCATENATE(C1, CHAR(32), D1, CHAR(32), CHAR(34), A1, CHAR(34), CHAR(32), E1, CHAR(32), CHAR(34), B1, CHAR(34))
'alternate with Office 365's TEXTJOIN¹
=TEXTJOIN(CHAR(32), FALSE, C1, D1, CHAR(34)&A1&CHAR(34), E1, CHAR(34)&B1&CHAR(34))
¹ The TEXTJOIN function was introduced with Excel 2016 with Office 365 or Excel Online.
Here is my code:
For i = Z To lastRow
Range("$A" & i).Select
ActiveCell.FormulaRC1C = "='Sheet1'!$A" & i
etc, etc.
The last line is having a problem (obviously) because I can't seem to figure out the quotes needed. How do I format the double quotes? Is there a better way to say this?
I don't think the quotes are the problem (they look OK). You're using the FormulaR1C1 method, which expects the address to be in R1C1 notation (e.g. R3C4), whereas you're supplying the address in e.g. C4.
Try using .Formula
There's no readable way to insert quote marks into code that generates a string. You can try triple-quotes - """ - and good luck with your debugging.
I tend to use the chr() function, with the knowledge that character 34 is the double-quote:
strQ = "He said: " & chr(34) & "It's a dead parrot" & chr(34)
strQ = strQ & ", and explained: " & "It has ceased to be" & chr(34) & "."
Debug.Print strQ
Will concatenate this string:
He said: "It's a dead parrot", and explained: "It has ceased to be".