简体   繁体   中英

VB.NET - Excel formula

Hi im trying to programmingly insert a formula into the cell using the following:

        With wbXl.Worksheets("Sheet2")
        .Cells(9, 2).Formula = "=SUMIFS(Running!C2:C999999,Running!B2:B999999,">=01/10/2014 00:00:00",Running!B2:B999999,"<=01/10/2014 23:59:59")"
    End With

Problem is that the " in the formula is playing havok with vb saying syntax error.

How would i get around that, any help would be great :)

Many Thanks, Pete

Use two double quotes to escape them. (basically apart from the first and last " make the rest be "")

.Cells(9, 2).Formula = "=SUMIFS(Running!C2:C999999,
Running!B2:B999999,"">=01/10/2014 00:00:00"",Running!B2:B999999,
""<=01/10/2014 23:59:59"")"

This should produce the following formula in the cell

=SUMIFS(Running!C2:C999999,Running!B2:B999999,">=01/10/2014 00:00:00",Running!B2:B999999,"<=01/10/2014 23:59:59")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM