Splitting IF statement in multiple lines in VBScript

excel, vba, vbscript

Solution

Yes you can break IF statement in multiple lines in vbscript. Here is a very basic example

If 1 = 1 Or _
2 = 2 Then

wscript.echo "See, It Works :)"

End If

or

If (UCase(Trim("1")) = "1") Or _
(UCase(Trim("2")) = "2") Then

wscript.echo "See, It Works :)"

End If

The error is somewhere else. Check your workbook objects and their values. Also check the values of `i`, `a` and `b`.

Problem

I was wondering if in VBScript I can break a `If` statement in multiple lines. Like: ``` If (UCase(Trim(objSheet.Cells(i, a).Value)) = "YES") Or _ (UCase(Trim(objSheet.Cells(i, b).Value)) = "NO") Then ' Do something End If ``` I tried this and got a syntax error as `If` expects a `Then` in the same line.

Original source