excel vba:代码中的换行符

时间:2016-01-27 22:18:00

标签: excel vba excel-vba

我在excel vba中有一个相当冗长的公式,我被迫分成多行。我尝试插入“_”但是我收到以下错误:

“编译错误:预期:声明结束”

我已多次查看此代码,似乎无法找到导致此错误的原因。如果有人可以查看下面的代码并帮我解决这个问题,我会非常感激。提前谢谢。

        If InStr(1, lineitem.Value, "Excess MO") > 0 And InStr(1, lineitem.Value, "AOS") > 0 Then
        lineitem.Offset(0, 16).Formula = "=SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R2C3&"" Claims'!B:B""),R[0]C[-19],INDIRECT(""'""&R2C3&"" Claims'!C:C""),R[0]C[-17],INDIRECT(""'""&R2C3&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-15],R[0]C[-14]),INDIRECT(""'""&R2C3&"" Claims'!P:P""),"">""&R5C3,INDIRECT(""'""&R2C3&"" Claims'!H:H""),""<>""&""NS""))- _
        SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R2C3&"" Claims'!B:B""),R[0]C[-19],INDIRECT(""'""&R2C3&"" Claims'!C:C""),R[0]C[-17],INDIRECT(""'""&R2C3&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-15],R[0]C[-14]),INDIRECT(""'""&R2C3&"" Claims'!P:P""),"">""&R5C3,INDIRECT(""'""&R2C3&"" Claims'!H:H""),""<>""&""NS"",INDIRECT(""'""&R2C3&"" Claims'!G:G""),R2C5:R2C27))- _
        SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R2C3&"" Claims'!B:B""),R[0]C[-19],INDIRECT(""'""&R2C3&"" Claims'!C:C""),R[0]C[-17],INDIRECT(""'""&R2C3&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-15],R[0]C[-14]),INDIRECT(""'""&R2C3&"" Claims'!P:P""),"">""&R5C3,INDIRECT(""'""&R2C3&"" Claims'!H:H""),""<>""&""NS"",INDIRECT(""'""&R2C3&"" Claims'!G:G""),R5C5:R5C54))"
        lineitem.Offset(0, 16).Value = lineitem.Offset(0, 16).Value
        lineitem.Offset(0, 17).Formula = "=SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R3C3&"" Claims'!B:B""),R[0]C[-20],INDIRECT(""'""&R3C3&"" Claims'!C:C""),R[0]C[-18],INDIRECT(""'""&R3C3&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-16],R[0]C[-15]),INDIRECT(""'""&R3C3&"" Claims'!P:P""),"">""&R5C3,INDIRECT(""'""&R3C3&"" Claims'!H:H""),""<>""&""NS""))- _
        SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R3C3&"" Claims'!B:B""),R[0]C[-20],INDIRECT(""'""&R3C3&"" Claims'!C:C""),R[0]C[-18],INDIRECT(""'""&R3C3&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-16],R[0]C[-15]),INDIRECT(""'""&R3C3&"" Claims'!P:P""),"">""&R5C3,INDIRECT(""'""&R3C3&"" Claims'!H:H""),""<>""&""NS"",INDIRECT(""'""&R3C3&"" Claims'!G:G""),R2C5:R2C27))- _
        SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R3C3&"" Claims'!B:B""),R[0]C[-20],INDIRECT(""'""&R3C3&"" Claims'!C:C""),R[0]C[-18],INDIRECT(""'""&R3C3&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-16],R[0]C[-15]),INDIRECT(""'""&R3C3&"" Claims'!P:P""),"">""&R5C3,INDIRECT(""'""&R2C3&"" Claims'!H:H""),""<>""&""NS"",INDIRECT(""'""&R3C3&"" Claims'!G:G""),R5C5:R5C54))"
        lineitem.Offset(0, 17).Value = lineitem.Offset(0, 17).Value
        End If

1 个答案:

答案 0 :(得分:7)

换行不会像那样工作。

您需要以下内容:

   fset(0, 16).Formula = "THISIS() + " & _
                         "REALLYLONG()"