+ Reply to Thread
Results 1 to 3 of 3

If statement question!

  1. #1
    Forum Contributor
    Join Date
    03-07-2013
    Location
    Montreal
    MS-Off Ver
    Excel 2007
    Posts
    274

    If statement question!

    Hello,

    if I do this:

    Please Login or Register  to view this content.
    The compiler accepts it.

    But if I do this:

    Please Login or Register  to view this content.
    Then the compiler complains by showing the latter lines in red!!!

    Sometimes I have several test conditions that are part of the same "if" statement!!!
    Personally I tend to want to compact the length of the "if" statement by layering its conditions
    one under the other for better view... its a personal thing I guess!

    So my question, is, in VBA, is it at all possible to do the "if" statement spread out on a few lines as shown in the latter example?

    Thanks for your help
    rn

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,442

    Re: If statement question!

    Please Login or Register  to view this content.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: If statement question!

    What TMS said... the key is that when you break a line up like that, you need an underscore "_" to tell VBA what is happening.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] If statement question
    By iceman2014 in forum Excel General
    Replies: 3
    Last Post: 07-28-2014, 07:41 AM
  2. Have question about using .find statement and brackets around After:= statement
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-09-2011, 03:28 PM
  3. IF statement question
    By lilsnoop in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-18-2008, 10:07 PM
  4. question with if statement
    By behrk2 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-23-2007, 10:45 AM
  5. IF then statement question
    By ChuckW in forum Excel General
    Replies: 2
    Last Post: 02-24-2006, 12:35 PM

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