简体   繁体   English

尝试插入带有Excel VBA公式的列

[英]Trying to insert a column with a formula for Excel VBA

I am trying to insert a column into my data table and insert a formula into the cells. 我试图在我的数据表中插入一列,并在单元格中插入一个公式。 This code has worked for me on this project except for this formula: 这段代码对我有效,但公式如下:

     With Data

            .Columns("M:M").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
            .Range("M1").FormulaR1C1 = "PROD-DESC"
            .Range("M2").FormulaR1C1 = "=CONCATENATE(K2," - ",L2)"
            .Range("M2:M" & .Cells(Rows.Count, "M").End(xlUp).Row).FillDown     


 End With

When I run the code. 当我运行代码时。 I get a mismatch error and it highlights the line with the concatenate formula. 我收到不匹配错误,并用串联公式突出显示了该行。

Any help would be greatly appreciated. 任何帮助将不胜感激。 I am really struggling to figure out why this is not working. 我真的很难弄清楚为什么这不起作用。

Thanks, 谢谢,

G G

以下代码将起作用(在另一个字符串中时,您需要将双引号引起来的双引号-您还需要删除R1C1 ):

.Range("M2").Formula = "=CONCATENATE(K2,"" - "",L2)"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM