1

I got syntax error for macro code in excel. Macro code below:

Sub concatnate()
'
' concatnate Macro
'
' Keyboard Shortcut: Ctrl+t
'
    ActiveCell.FormulaR1C1 = _
        "=CONCATENATE("","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""& _
        "","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","")"
    Range("C1").Select
    Selection.Copy
    Range("C3").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Cells.Replace What:=",,", Replacement:="", LookAt:=xlPart, SearchOrder _
        :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End Sub
1
  • i made some changes in code then syntax error resolved but i did not get the exact result new is- Commented Sep 15, 2015 at 14:47

2 Answers 2

2

It's pretty simple, really.

You can't put double quotes INSIDE a set of double quotes.

You need to replace all those inner quotes with double-double quotes

ActiveCell.FormulaR1C1 = _
        "=CONCATENATE("""","""")"

As per comment, this answer has been corrected.

Sign up to request clarification or add additional context in comments.

2 Comments

This is Excel VBA, not ASP Classic or T-SQL. The single quotes are not going to work as an alternative.
You, sir, are correct. So I tried a couple of different things. It seems that double-double quotes is the correct way to do this.
1

It seems that the VBE is getting a little confused trying to make sense of all those commas. It can be corrected as,

ActiveCell.FormulaR1C1 = _
    "=CONCATENATE("","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""," & _
                 ""","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","")"

If all you want is 99 commas then the following might be better.

ActiveCell.FormulaR1C1 = "=REPT(CHAR(44), 99)"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.