Closed Thread
Results 1 to 8 of 8

How do I break VBA code into two or more lines?

  1. #1
    Kasama
    Guest

    How do I break VBA code into two or more lines?

    Using Excel 2003/Windows XP/VBA Editor 6.3.
    I have some very long lines which don't fit in the VBA Editor window and to
    make the code easier to read I want to break them into two or more lines.
    I was told to type a space then and underscore but this doesn't work.
    (I am not talking about breaking the lines in Message Boxes).

  2. #2
    Harald Staff
    Guest

    Re: How do I break VBA code into two or more lines?

    Of course it works.

    If Day(Date) > 10 _
    And Hour(Time) > 20 Then _
    MsgBox "It is after the tenth " & _
    "and it is evening"

    HTH. Best wishes Harald

    "Kasama" <[email protected]> skrev i melding
    news:[email protected]...
    > Using Excel 2003/Windows XP/VBA Editor 6.3.
    > I have some very long lines which don't fit in the VBA Editor window and

    to
    > make the code easier to read I want to break them into two or more lines.
    > I was told to type a space then and underscore but this doesn't work.
    > (I am not talking about breaking the lines in Message Boxes).




  3. #3
    Niek Otten
    Guest

    Re: How do I break VBA code into two or more lines?

    <I was told to type a space then and underscore >

    and then press ENTER

    --
    Kind regards,

    Niek Otten
    Microsoft MVP - Excel

    "Kasama" <[email protected]> wrote in message news:[email protected]...
    | Using Excel 2003/Windows XP/VBA Editor 6.3.
    | I have some very long lines which don't fit in the VBA Editor window and to
    | make the code easier to read I want to break them into two or more lines.
    | I was told to type a space then and underscore but this doesn't work.
    | (I am not talking about breaking the lines in Message Boxes).



  4. #4
    Duncan
    Guest

    Re: How do I break VBA code into two or more lines?

    I think Kasama has probably tried to break inbetween words maybe?

    only break after complete words, (as harolds example shows) for some
    reason it gets confused otherwise!
    Duncan


    Harald Staff wrote:
    > Of course it works.
    >
    > If Day(Date) > 10 _
    > And Hour(Time) > 20 Then _
    > MsgBox "It is after the tenth " & _
    > "and it is evening"
    >
    > HTH. Best wishes Harald
    >
    > "Kasama" <[email protected]> skrev i melding
    > news:[email protected]...
    > > Using Excel 2003/Windows XP/VBA Editor 6.3.
    > > I have some very long lines which don't fit in the VBA Editor window and

    > to
    > > make the code easier to read I want to break them into two or more lines.
    > > I was told to type a space then and underscore but this doesn't work.
    > > (I am not talking about breaking the lines in Message Boxes).



  5. #5
    Ron de Bruin
    Guest

    Re: How do I break VBA code into two or more lines?

    Hi Kasama

    Like this

    Sub Mail_workbook_1()
    ActiveWorkbook.SendMail "[email protected]", _
    "This is the Subject line"
    End Sub


    See the space between the , and the _



    --
    Regards Ron de Bruin
    http://www.rondebruin.nl



    "Kasama" <[email protected]> wrote in message news:[email protected]...
    > Using Excel 2003/Windows XP/VBA Editor 6.3.
    > I have some very long lines which don't fit in the VBA Editor window and to
    > make the code easier to read I want to break them into two or more lines.
    > I was told to type a space then and underscore but this doesn't work.
    > (I am not talking about breaking the lines in Message Boxes).




  6. #6
    Harald Staff
    Guest

    Re: How do I break VBA code into two or more lines?

    "Niek Otten" <[email protected]> skrev i melding
    news:%[email protected]...
    > <I was told to type a space then and underscore >
    >
    > and then press ENTER
    >
    > --
    > Kind regards,
    >
    > Niek Otten
    > Microsoft MVP - Excel


    Lol. That may be the problem, yes.
    MVP! Really glad to hear that, Niek.

    Best wishes Harald



  7. #7
    Kasama
    Guest

    Re: How do I break VBA code into two or more lines?

    Tks, but that wasn't it. After typing Space+Underscore+Enter I was getting
    "Invalid Character" error messages for the underscore. So I tried copying and
    pasting your code and Harald Staff's code into blank macros. This time VBE
    accepted the underscores, and then broke the line when I typed ' _enter'. No
    more error messages.
    But then I noticed a strange thing: up till now VBE has automatically placed
    a line of underscores between my Sub procedures -- if I typed 'Sub' on a new
    line after
    'End Sub' I a dividing line of underscores automatically appeared.
    These have now disappeared from all existing macros!
    So it seems to me as if 'underscore' was assigned to a dividing line, and
    after pasting in your code, VBE has reassigned unserscore to 'line continues
    on next'.

    Thanks

    Kasama

    "Niek Otten" wrote:

    > <I was told to type a space then and underscore >
    >
    > and then press ENTER
    >
    > --
    > Kind regards,
    >
    > Niek Otten
    > Microsoft MVP - Excel
    >
    > "Kasama" <[email protected]> wrote in message news:[email protected]...
    > | Using Excel 2003/Windows XP/VBA Editor 6.3.
    > | I have some very long lines which don't fit in the VBA Editor window and to
    > | make the code easier to read I want to break them into two or more lines.
    > | I was told to type a space then and underscore but this doesn't work.
    > | (I am not talking about breaking the lines in Message Boxes).
    >
    >
    >


  8. #8
    Registered User
    Join Date
    04-19-2012
    Location
    Leeds, England
    MS-Off Ver
    Office for Mac 2011
    Posts
    17

    Re: How do I break VBA code into two or more lines?

    I often got this error if i put the underscore in the middle of a msgbox text (not so that it was on 2 lines in the msgbox but in the code). I think it has to be outside of ""

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1