Sumit Jain
Sumit Jain

Reputation: 377

Insert function is giving 1004 error in excel macro vba

Below code is giving error (1004)

 Sheets(2).Cells(i, 7).Formula = "=LEFT(" & Sheets(2).Cells(i, 5) & ",2)"

Upvotes: 0

Views: 42

Answers (1)

bobajob
bobajob

Reputation: 1192

You are passing the value of a cell to LEFT, which expects either a cell reference or a string (including the quotation marks). Try

Sheets(2).Cells(i, 7).Formula = "=LEFT(" & Sheets(2).Cells(i, 5).Address & ",2)"

or

Sheets(2).Cells(i, 7).Formula = "=LEFT(""" & Sheets(2).Cells(i, 5) & """,2)"

instead.

Upvotes: 2

Related Questions