GCC
GCC

Reputation: 295

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

Upvotes: 0

Views: 1968

Answers (1)

Chris Mack
Chris Mack

Reputation: 5208

The following will work (you need to double the double quotes as you're inside another string - you also need to remove R1C1):

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

Upvotes: 2

Related Questions