我在excel中遇到宏代码的语法错误。下面的宏代码:
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
答案 0 :(得分:2)
这很简单,真的。
你不能把双引号INSIDE放在一组双引号中。
您需要用双引号替换所有内部引号
ActiveCell.FormulaR1C1 = _
"=CONCATENATE("""","""")"
根据评论,此答案已得到纠正。
答案 1 :(得分:1)
似乎VBE在尝试弄清楚所有这些逗号时有点困惑。它可以更正为,
ActiveCell.FormulaR1C1 = _
"=CONCATENATE("","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""," & _
""","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","")"
如果您只想要99个逗号,那么以下内容可能会更好。
ActiveCell.FormulaR1C1 = "=REPT(CHAR(44), 99)"