Too long code? [SOLVED]

  • Please defog my little mind - I'm getting an error message:


    'Expected: line number or label or statement or end of statement.'



    If Target.Value <> 1 And Target.Value <> 2 and so on with numbers 3 through 109 And Target.Value <> 110 Then Exit Sub


    The problem appears to be that the line wraps and I have missed something at the beginning of the second line. Everything worked fine when 'If Target.Value <> # consisted of one line of code. Problem began when I added too much to stay on one line.


  • Did you use the line continuation (space underscore space)?


    Software: OpenOffice 3.0/NeoOffice 3.0 on Mac OS X 10.5.6
    Humanware: Older than dirt


    Old, slow, and confused - but at least I'm inconsistent!


    Rich
    (retired Excel 2003 user, 3.28.2008)

  • split your lines...


    eg

    Code
    If Target.Value <> 1 And _  Target.Value <> 2


    use 'space' _ 'space' at the end of a line & press RETURN to carry on code


    (Hey, but do you really need all those IFs ?? what about &gt; and < or Select Case??)

  • 1) At the end of each line put a space then a _ (underscore)


    2) "If Target.Value <> 1 And Target.Value <> 2 and so on with numbers 3 through 109 And Target.Value <> 110 Then Exit Sub"
    Could you replace this long code with:
    If target.value<1 or target.value&gt;110 then end sub?


    EDIT: [You guys are too fast :) ]

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!