简体   繁体   中英

Check if any value from a range of values is present in a single cell

The crux of the issue is that I am having trouble checking to see if any single value from a range of values is present in a single cell.

I have a CustomerList sheet with raw data information about the accounts. I am creating a RiskAssessment report within the workbook to parse the account information and bubble up accounts that meet certain criteria so they can be flagged for interaction. The information is an export from our CRM and I cannot change the format of the data that comes out.

The customer data looks like this:

Account | Signing Date | Previous  | Type          | ...
---------------------------------------------------------
Yellow  | 01/01/20     | Banana    | One;Two       | 
Blue    | 02/01/20     | Banana    | Two           | 
Black   | 03/01/20     | Orange    | Two;Three     | 
Red     | 04/01/20     | Blueberry | One;Two;Three |
White   | 05/01/20     | Cherry    | One;Four      | 
...

The RiskAssessment report is a similar format where each column represents a risk factor and each cell will have some number of points based on if certain criteria is met with the account. The point values will be summed and hopefully higher risk accounts are more visible. The point values are pulled from a RiskFactors sheet.

The RiskFactors sheet looks like this:

Factor        | Points | Values    |     |      | ...
------------------------------------------------------
New Customer  | 1      | Banana    |     |      |
Few Products  | 2      | Banana    |     |      |
Small Account | 4      | Orange    |     |      |
Type          | 4      | One       | Two | Five |
Last Contact  | 5      | Blueberry |     |      |
Version       | 3      | Cherry    |     |      |
...

Some risk factors are single values (boolean) and some are lists with only a certain number of options in the list being things I'm checking for. I'm am trying to do a lookup on the raw data (matching the account name), pull some information from a specified column, and then process it. I am getting FALSE for every single formula when I don't feel like I should be.

Current iteration of the formula:

=SUMPRODUCT(--ISNUMBER(SEARCH(RiskFactors!$C$4:$D$4,CELL("address",INDEX(CustomerList!B:I,MATCH($A2,CustomerList!A:A,0),3)))))>0

Specifically I'm working with the Type column. You can see the format out of the CRM is a list of values separated by semicolons. I manually choose which possible values are considered a risk and I put those in separate cells on the RiskFactors sheet. I have complete control over the RiskAssetment and RiskFactors sheets and this is how I started off setting it up trying to create the report.

I built this from a combination of this help page (cell contains one of many things) and this help page (get address of lookup result). I haven't started on wrapping it in an IF statement yet because I can't get it to evaluate TRUE/FALSE correctly for whether or not any value from the risk range is contained in the account information.

I also split up the formulas into two parts when trying to debug and found that it starts to fail when I use the CELL function.

If I run the CELL function alone, I get the correct cell reference.

=CELL("address",INDEX(CustomerList:B,I,MATCH($A2:CustomerList,A,A,0),3))

If I manually put the cell reference in the SUMPRODUCT function, I get the right TRUE/FALSE.

=SUMPRODUCT(--ISNUMBER(SEARCH(RiskFactors:$C$4,$D$4,CustomerList!$D$21)))>0

But when I combine them everything is FALSE.

Any ideas why everything is evaluating to FALSE?

The problem is here:

CELL("address",

I misunderstood what address does. It returns the address of the cell as text . (It's clearly stated as such in the documentation, but I apparently did not grasp this.) I need the contents of the cell to search through instead of searching through text which consists of the cell's address.

Switching from address to contents makes this work.

The final working formula:

=SUMPRODUCT(--ISNUMBER(SEARCH(RiskFactors!$C$4:$D$4,CELL("contents",INDEX(CustomerList!B:I,MATCH($A2,CustomerList!A:A,0),3)))))>0

If you find yourself in need of checking if any value from a range of values is present in a single cell, where the single cell location is not obvious and needs to be dynamically located (typically with a VLOOKUP or INDEX MATCH ), this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM