In Google Sheets, I have a list of unique strings that I want to filter based on two conditions. These conditions are two strings within that list. Ultimately, I want to find all the strings, inclusive of my conditions, that are in between.
This is the list in the Google Sheet:
| List |
|---|
| Apple |
| Banana |
| Pear |
| Grapes |
| Kiwi |
| Mandarin |
| Papaya |
| Orange |
| Tomato |
| Plum |
| Watermelon |
Based on these two following conditions, I'm trying to get strings that fall in between these two, including these two conditions.
| String 1 | String 2 |
|---|---|
| Pear | Orange |
Ideally, the results will be displayed as an array, that way, the single formula can dynamically change the results based on the 2 conditions.
| Expected Results |
|---|
| Pear |
| Grapes |
| Kiwi |
| Mandarin |
| Papaya |
| Orange |
In terms of error handling, I need to account for 3 type of scenarios:
1. Scenario 1: Error handling when selected conditions not in list order
Conditions:
| String 1 | String 2 |
|---|---|
| Plum | Kiwi |
| Expected Results |
|---|
| Nothing |
--> Nothing between string selection as String 2 is BEFORE String 1 condition in the list order.
2. Scenario 2: Error handling when String conditions match
Conditions:
| String 1 | String 2 |
|---|---|
| Mandarin | Mandarin |
| Expected Results |
|---|
| Mandarin |
--> the list of strings are unique, so it will show only one result as it's inclusive of string conditions.
3. Scenario 3: Error handling when String condition #2 is empty, therefore choosing all results post-String 1 that are not empty.
Conditions:
| String 1 | String 2 |
|---|---|
| Mandarin |
| Expected Results |
|---|
| Mandarin |
| Papaya |
| Orange |
| Tomato |
| Plum |
| Watermelon |
Attempts:
I've tried the following 2 formulas but unfortunately I get an error as strings are not considered as numbers in the QUERY function, and the OFFSET attempt doesn't allow me to enter in between.
1.=QUERY(A4:A14,"SELECT Col1 WHERE Col1 >= '"&C4&"' AND Col 1 <= '"&D4&"'")
2.=OFFSET(A4:A14, MATCH(C4, A4:A14, 0), 0)
Testing Google Sheet link with public edit access: here
