Search code examples
vbaexcelexcel-2013

Concatenate formula with rowcount


I am trying to enter a CONCATENATE formula in a cell with VBA. But the result it writes keep returning false... I need to use a rowcount, since the table grows longer and I need it for THAT row.

This is the latest code I tried, again to no avail:

.Offset(RowCount, 0) = Formula = "=CONCATENATE(P" & RowCount & "J" & RowCount & "DG" & RowCount

Any suggestions would be greatly appreciated.


Solution

  • You're not creating your string properly and you need to change = Formula = to .Formula =. Also, I'm assuming RowCount is defined somewhere?

    Change:

    .Offset(RowCount, 0) = Formula = "=CONCATENATE(P" & RowCount & "J" & RowCount & "DG" & RowCount
    

    To:

    .Offset(RowCount, 0).Formula = "=CONCATENATE(P" & RowCount & ",J" & RowCount & ",DG" & RowCount & ")"