Peter James
Peter James

Reputation: 103

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

Upvotes: 0

Views: 1026

Answers (1)

Dave Brown
Dave Brown

Reputation: 500

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")

Upvotes: 1

Related Questions