ChangeWorld
ChangeWorld

Reputation: 431

Write properly a formula in Excel VBA

I already asked a question like this before, but seems that the answer given is not working in this case

this is my code:

Worksheets("Sheet").Range(myRange).formula = "=CONCATENATE(CODICI!" & stringCodiceCella & ";" & stringDesignazioneCella & ")"

Note that stringCodiceCella is a String, and stringDesignazioneCella is also a String.

Following this link A working example of formula in VBA

I can't see the error.

Upvotes: 0

Views: 54

Answers (1)

shrivallabha.redij
shrivallabha.redij

Reputation: 5902

You can use "," in place of ";" as suggested by @BigBen

Worksheets("Sheet").Range(myRange).Formula = "=CONCATENATE(CODICI!" & stringCodiceCella & "," & stringDesignazioneCella & ")"

Or use FormulaLocal

Worksheets("Sheet").Range(myRange).FormulaLocal = "=CONCATENATE(CODICI!" & stringCodiceCella & ";" & stringDesignazioneCella & ")"

Edit: See below code.

Worksheets("Sheet").Range(myRange).Formula = "=CONCATENATE(CODICI!" & stringCodiceCella & ",""-""," & stringDesignazioneCella & ")"

Worksheets("Sheet").Range(myRange).FormulaLocal = "=CONCATENATE(CODICI!" & stringCodiceCella & ";""-"";" & stringDesignazioneCella & ")"

Upvotes: 1

Related Questions