Jain
Jain

Reputation: 999

Formula works in excel but not in vba

the below formula works in a cell, but when I try to use it in VBA it gives syntax error. Why is it and what is the solution?. Thanks.

ThisWorkbook.Sheets("Sheet2").Cells(Lastrow + 1, 9).Formula = "=(SUMIFS(Sheet1!$B:$B,Sheet1!$O:$O,">0")/SUM(Sheet1!$B1:$B1000))*100"

Upvotes: 1

Views: 1377

Answers (2)

The Gambill
The Gambill

Reputation: 181

You need to use single quotes for the string otherwise the string ends and will throw an error but there may be something else going on. What is your exact error?

Upvotes: -1

DragonSamu
DragonSamu

Reputation: 1163

The problem is with ">0" to use quotations inside a String you need to do the following:

"">0"" with double quotations VBA understands its a String inside the String.
instead of the end " of the String >0 some code and " the start of a new String.

Upvotes: 6

Related Questions