+ Reply to Thread
Results 1 to 10 of 10

Using an Array within AND/OR Functions

  1. #1
    Registered User
    Join Date
    03-30-2017
    Location
    Manchester, UK
    MS-Off Ver
    Windows 10
    Posts
    8

    Using an Array within AND/OR Functions

    So, I'll start by saying this is not a serious issue, but more of a curiosity that I'm hoping someone can help answer for me.

    I came across a thread on another forum which included an answer where the OR statement was expressed as follows:

    Please Login or Register  to view this content.
    Rather than the more traditional:

    Please Login or Register  to view this content.
    Now, I don't know why, but seeing it expressed as an array appeals more to me [OCD?] so I have been using it recently. However, I came across a situation where it doesn't work like-for-like and I'm not sure why ... hence this post ... answers on a postcard please folks.

    Please Login or Register  to view this content.
    Is it because i'm using the less than/greater than operators? I've also tried expressing it as follows but still no good:

    Please Login or Register  to view this content.
    Thanks in advance,
    Bob

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Using an Array within AND/OR Functions

    Array {} can't contain functions or operators. It can be only string or numeric values.

    So...
    Please Login or Register  to view this content.
    Works, but not.
    Please Login or Register  to view this content.
    Basically whatever is inside array is treated as either literal string or numeric value.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Using an Array within AND/OR Functions

    Hi,

    Interesting question (for a change! ).

    Yes - such operators are invalid when employed as such. You would need to use e.g. COUNTIF:

    =AND(COUNTIF(I2,{">=2","<=5"}))

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  4. #4
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: Using an Array within AND/OR Functions

    If you literally say what you're trying to express, you'll understand the reason this fails in the syntax you have it: I2 is EQUAL to LESS THAN or EQUAL to 2, or I2 is EQUAL to GREATER THAN or EQUAL to 5.

    Something like COUNTIF would be needed.
    Spread the love, add to the Rep

    "None of us are as smart as all of us."

  5. #5
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Using an Array within AND/OR Functions

    Welcome to the board.

    Yes that really only works for straight A=B comparisons.

    That one needs to be the standard format
    =AND(I2>=2,I2<=5)

  6. #6
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Using an Array within AND/OR Functions

    Quote Originally Posted by CK76 View Post
    Array {} can't contain functions or operators. It can be only string or numeric values.
    Functions, no, but operators, yes, when employed within the IF(S) family of functions.

    Regards

  7. #7
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Using an Array within AND/OR Functions

    It can when employed within the IF(S) family of functions.
    True, but it's IF(s) family of function's treatment of literal string that makes the difference I believe.

    Below isn't valid syntax, for an example.
    Please Login or Register  to view this content.
    But below is.
    Please Login or Register  to view this content.

  8. #8
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Using an Array within AND/OR Functions

    Quote Originally Posted by CK76 View Post
    True, but it's IF(s) family of function's treatment of literal string that makes the difference I believe.
    Agreed.

    Quote Originally Posted by CK76 View Post
    Below isn't valid syntax, for an example.
    Please Login or Register  to view this content.
    Going slightly off-topic now, but just to show that we can generate the necessary construction with a little work:

    =SUMPRODUCT(COUNTIFS(B2,{">","<"}&D1:E1))

    Regards

  9. #9
    Registered User
    Join Date
    03-30-2017
    Location
    Manchester, UK
    MS-Off Ver
    Windows 10
    Posts
    8

    Re: Using an Array within AND/OR Functions

    Thanks all for the quick replies.

    At least you have all pretty much validated what I thought!!

    So the follow on question is: which one is more process efficient? I'm assuming that although the array is slightly simpler to type out, because it's an array, it will ultimately use more resource when used across large datasets (1 million+ records)?

  10. #10
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Using an Array within AND/OR Functions

    Can you give a practical example of what you'd like to achieve over such a large dataset?

    Since both the straight comparison and the COUNTIF construction must each process two clauses, I wouldn't have thought there'd be much difference between the two. Though I haven't tested this.

    Regards

+ 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] More about VBA FUNCTIONS AND ARRAY ?
    By hemesh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-06-2014, 02:46 PM
  2. Array from an Array using Index VBA functions
    By cmore in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2013, 09:33 AM
  3. VBA – User Designed Functions (UDF) - Renaming array functions
    By hbsonly in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-03-2013, 02:00 PM
  4. Replies: 1
    Last Post: 02-10-2012, 05:27 PM
  5. using excel array functions on part of array
    By chewwy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2009, 07:19 AM
  6. Replies: 2
    Last Post: 07-13-2006, 11:30 PM
  7. Array Functions
    By Jaytee in forum Excel General
    Replies: 11
    Last Post: 09-12-2005, 07:05 PM
  8. Array functions
    By rmellison in forum Excel General
    Replies: 8
    Last Post: 09-09-2005, 05:05 AM

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