+ Reply to Thread
Results 1 to 5 of 5

[SOLVED] Syntax for Writing Long VBA Formula on Multiple Lines

  1. #1
    Registered User
    Join Date
    02-15-2011
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    21

    [SOLVED] Syntax for Writing Long VBA Formula on Multiple Lines

    Hi,

    I have a large formula I am trying to input that is making me put it on two lines. I cannot get the syntax to work properly and was looking for some assistance. The range and actual formula all work properly, I am just looking for how to break the formula onto multiple lines in VBA.

    Please Login or Register  to view this content.
    Many thanks in advance for your help!

    Regards,
    nwd9s
    Last edited by pike; 06-13-2011 at 07:01 AM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Syntax for Writing Long VBA Formula on Multiple Lines

    When you break a long formula, you have to catenate the sub strings:

    Please Login or Register  to view this content.
    It's much easier to debug if you assign the formula to a string, and print the string to the Immediate window for perusal.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    05-13-2011
    Location
    New Zealander in London
    MS-Off Ver
    Excel 2007
    Posts
    74

    Re: Syntax for Writing Long VBA Formula on Multiple Lines

    Quote Originally Posted by nwd9s View Post
    Hi,

    I have a large formula I am trying to input that is making me put it on two lines.
    To break a long line of code into multiple lines in VBA, you use a space, then the the underscore character (i.e. " _").

  4. #4
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Syntax for Writing Long VBA Formula on Multiple Lines

    Hi tarquinious,

    From what I have tried before the " _" only works for vba code not a formula. What shg suggested is correct. You need to close the first line with a quotation mark, add a space and an & sign then on the new line start with quotation marks.

    abousetta

  5. #5
    Registered User
    Join Date
    02-15-2011
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Syntax for Writing Long VBA Formula on Multiple Lines

    Thanks for your help. I have tested this, and a " & _ needs to be used for splitting a formula in vba.

    Thanks,
    nwd9s

+ Reply to 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