Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

Finding strings from a list between 2 string conditions that are part of the list

$
0
0

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 1String 2
PearOrange

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 1String 2
PlumKiwi
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 1String 2
MandarinMandarin
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 1String 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

Image of current worksheet: enter image description here


Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>