+ Reply to Thread
Results 1 to 4 of 4

Tidying a messy compound if statement - is there a better way?

  1. #1
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Tidying a messy compound if statement - is there a better way?

    Hi All,

    Quick question for you; I have a compound if statement that I'm using in some code but it's a bit messy and I was wondering if there is a way to tidy it up or a better way of doing it.

    The code needs to test if one of two scenarios are met them carry out a task - the same tast for the two scenarios. Both scenarios have multiple criteria with much of it shared between the two but one difference meaning an additional criteria needs to be checked. In this example 'C':

    Please Login or Register  to view this content.
    Ideally it would be good to have it exit the statement if A<>1 and I have heard you can use AndAlso and OrElse, but I have not come across them before and not sure how to construct a statement with them.

    Any alternative ideas appreciated.

    Thanks, TC

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Tidying a messy compound if statement - is there a better way?

    There are different approaches but you can use nested If statements:
    Please Login or Register  to view this content.
    for example. You may also want to look at Select Case statements if you are not familiar with them.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Tidying a messy compound if statement - is there a better way?

    Please Login or Register  to view this content.
    If solved remember to mark Thread as solved

  4. #4
    Forum Contributor
    Join Date
    10-22-2012
    Location
    London, UK
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    162

    Re: Tidying a messy compound if statement - is there a better way?

    Hi RomperStomper and Patel45

    Thanks for coming back on this. I like the idea of nesting the if's so each criteria is checked in turn and I forgot about brackets so thanks for the reminder.
    Am familar with Select Case statements and this If is actually inside a case. Not sure there is any real benefit in susing one in this instance.

    Thanks again, TC

+ 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. tidying up code
    By tryer in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-14-2011, 10:03 AM
  2. Tidying up a formula
    By Mediaid in forum Excel General
    Replies: 2
    Last Post: 03-30-2011, 07:02 PM
  3. Compound if statement
    By coool in forum Excel General
    Replies: 1
    Last Post: 11-02-2010, 02:07 PM
  4. Compound IF statement
    By mdemmel in forum Excel General
    Replies: 1
    Last Post: 12-30-2008, 05:52 PM
  5. Problem with compound IF statement
    By Phillycheese5 in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 07-18-2005, 03:59 PM

Tags for this Thread

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