The issue with your formula stems from using the MID function directly on a range ($B$1:$B$117). The MID function is designed to work with single cell references, not ranges. To achieve your goal of checking if a substring from A1 exists within a range of substrings in B1:B117, you have a few options:
Option 1: Using a Helper Column
-
Create a Helper Column:
- In column
C (starting from C1), enter the following formula to extract the substring from each cell in B1:B117:
=MID(B1, 6, LEN(B1) - 5)
- Drag this formula down from
C1 to C117. This will give you the necessary substrings from the B column.
-
Use the MATCH Function with the Helper Column:
- Now, modify your original formula to search within the helper column:
=IF(
ISNUMBER(MATCH(MID(A1, 6, LEN(A1) - 5), $C$1:$C$117, 0)),
MID(A1, 6, LEN(A1) - 5),
"No Match"
)
- Explanation:
MID(A1, 6, LEN(A1) - 5): Extracts the substring from A1 starting at the 6th character.
MATCH(..., $C$1:$C$117, 0): Searches for the extracted substring within the helper column.
ISNUMBER(...): Checks if a match is found.
IF(...): Returns the substring if a match is found; otherwise, returns "No Match".
Option 2: Using an Array Formula
If you prefer not to use a helper column, you can use an array formula. Here's how:
-
Enter the Following Formula:
=IF(
SUMPRODUCT(--(MID($B$1:$B$117, 6, LEN($B$1:$B$117) - 5) = MID(A1, 6, LEN(A1) - 5))) > 0,
MID(A1, 6, LEN(A1) - 5),
"No Match"
)
-
Confirm as an Array Formula:
- In older versions of Excel (before Office 365), you need to enter this formula by pressing Ctrl + Shift + Enter instead of just Enter.
- In newer versions (Office 365 and later), Excel handles array formulas automatically.
Explanation:
MID($B$1:$B$117, 6, LEN($B$1:$B$117) - 5): Extracts the substrings from each cell in B1:B117.
MID(A1, 6, LEN(A1) - 5): Extracts the substring from A1.
--(...): Converts TRUE/FALSE results to 1/0.
SUMPRODUCT(...) > 0: Checks if there's at least one match.
IF(...): Returns the substring if a match exists; otherwise, returns "No Match".
Option 3: Using the FILTER Function (Excel 365 and Later)
If you're using Excel 365 or a later version that supports dynamic arrays, you can utilize the FILTER function:
-
Enter the Following Formula:
=IF(
COUNT(FILTER(MID($B$1:$B$117, 6, LEN($B$1:$B$117) - 5), MID($B$1:$B$117, 6, LEN($B$1:$B$117) - 5) = MID(A1, 6, LEN(A1) - 5))) ) > 0,
MID(A1, 6, LEN(A1) - 5),
"No Match"
)
Explanation:
FILTER(...): Filters the substrings from B1:B117 that match the substring from A1.
COUNT(...) > 0: Checks if there are any matches.
IF(...): Returns the substring if a match exists; otherwise, returns "No Match".
Summary
Your original formula doesn't work as expected because MID cannot process a range directly. By either using a helper column, an array formula with SUMPRODUCT, or leveraging the FILTER function in newer Excel versions, you can achieve the desired functionality.
Choose the option that best fits your version of Excel and your comfort level with these functions.
Corrected Formula Using a Helper Column:
-
In C1, enter:
=MID(B1, 6, LEN(B1) - 5)
-
Drag the formula down to C117.
-
Then, use the following formula:
=IF(ISNUMBER(MATCH(MID(A1, 6, LEN(A1) - 5), $C$1:$C$117, 0)), MID(A1, 6, LEN(A1) - 5), "No Match")
This approach avoids applying MID directly to a range and ensures the formula works as intended.