Excel: Print Values from Column A not found in Col

2019-08-05 08:59发布

问题:

I have tried finding this solution on the web but have not had success for this specific problem. In Excel 2010 I have some data in column A where each value may partially contain data in column B.

EX:
Column A might contain "http://google.com/webmasters"
Column B might contain "google.com"
This should give me a match.

I want to print in Column C all values in column A that do not contain any values from column B.

EX:
Column A

http://dir.mydomain.tdl
http://myotherdomain.tdl
http://blog.otherdomain.tdl
http://www.lastdomain.tdl

Column B

mydomain.tdl
lastdomain.tdl

Column C (results required)

http://myotherdomain.tdl
http://blog.otherdomain.tdl

Any help would be greatly appreciated.

回答1:

I think I have the solution using ARRAY formula. Assuming your input AND that columns A-C have titles, or simply, strings are listed starting cells A2 and B2, do the following:

  1. C2: type the formula =IF(OR(NOT(ISERROR(SEARCH(INDIRECT("B2:B"&(COUNTA($B:$B))),$A2)))),"",$A2) but press CTRL+SHIFT+ENTER instead of usual ENTER - this will define an ARRAY formula and will result in {} brackets around it (but do NOT type them manually!).
  2. Autofill formula in C2 until the end of list in column A, e.g. if the last value is in A100, then autofill up to C100 (how long column B does not matter here).
  3. You may then copy & paste obtained results as values and sort out empty strings.

Here you go! The key here - we check every string in column A for having at least one match among array of strings in column B, and return empty string in case at least one match found.

For your convenience sample file is shared: https://www.dropbox.com/s/janf0xxon4z2yh5/DomainsLookup.xlsx



回答2:

Maybe not the must efficient but you could simply use two arrays - one for Column A and one for Column B. Iterate through ColumnA array to see if it exists in ColumnB array (use Array.IndexOf or .contains). If it does you could remove it from the ColumnA array and output the remaining values in Column C as the remainder.