Question

I want to search into an entire column for mismatches (type-errors I made) compared to the available types I've defined. And in case there are any mismatches I want to have the cell of that mismatch displayed in the cell below.

So this is what I have (I replaced the actual types with synonyms for privacy reasons, obviously they aren't named type# irl):

Column E : E

  • type1 (E1)
  • type5 (E2)
  • type3 (E3)
  • type3 (E4)
  • type7 (E5)
  • tipe2 (E6)
  • type9 (E7)
  • (E8)
  • type3 (E9)

Column K2 : K10

  • type1 (K2)
  • type2 (K3)
  • type3 (K4)
  • type4 (K5)
  • type5 (K6)
  • type6 (K7)
  • type7 (K8)
  • type8 (K9)
  • type9 (K10)

For example puposes I made the type-error "tipe2" in cell E6 and also added an empty row in cell E8. Now I want a formula which displays "Error" when something in column E:E does not match one of the types in column K2:K10, and else print either nothing or "no error found". And at the same time I want in a seperate cell the coordinates (in this case E6) of the mismatching cell.

I've already got the part to get the mismatching cell, where my_string should be replaced with the mismatching string that has been found:

="E"&MATCH("my_string",E:E,FALSE)+IF(COUNTIF(E:E,"my_string")=1,0,COUNTIF(E:E,"my_string")-1)

PS: I don't want a VBA script! I just want formulas inside two cells. One to see wether or not I made a mismatch, and incase I did made a mismatch I want the Cell's coordinates (or the last Cell's when multiple mismatches are found).

Était-ce utile?

La solution

You can use a so-called array formula to achieve this. As an illustration, I simulated your situation in this image:

Excel picture of situation

The important cell is H1, which contains the index of the offending cell in column E. For the sake of simplicity, I introduced two named ranges items, containing cells E1:E9 and lookup containing cells K2:K10. The formula in H1 is

=MAX(IF(ISBLANK(items),0,IF(ISERROR(MATCH(items,lookup,0)),ROW(INDIRECT("1:"&ROWS(items))),0)))

This is an array formula, which means that you have to confirm with Ctrl-Shift-Enter. If you did that right, the formula will show curly brackets around it -- you do not type those yourself. This formula goes over all cells in the range called items, creates an array with the value 0 for all cells that are blank or that have a match in the range called lookup. For the remaining cells, the value inserted is equal to the row number. Then the maximum is taken over that.

As a result, H1 will contain the index of the last offending item. If all items are OK, then the value 0 is displayed.

Cell G1 shows Error if any offending item has been found, and OK otherwise. The formula is

=IF(H1=0,"OK","Error")

Finally, I1 displays the actual offending item via

=IF(H1>0,INDEX(items,H1),"")

If you do not want to use the named ranges, then replace items with $E$1:$E$9 and lookup with $K$2:$K$10.

If the offending cell is an empty cell, then I1 will contain the value 0.

I think the value in H1 is useful for analysis, but if you do not want it, you can hide it. Or you can fold that formula in the ones used in G1 and I1, but the formulas become pretty complicated.

A workbook containing this answer is uploaded here

As a note on the side: are you aware that you can use Excel's data validation feature with a drop-down list to avoid these kinds of typos you are looking at. That might be useful for you. An example is given in the article Drop-Down Using Data Validation in Microsoft Excel

Autres conseils

The Easiest way to do this is; to use the filter "Does not contain"

Excel 2010 solution, similar for 2003

  • Select the whole column
  • Select Data
  • Select Filter
  • Select filter option (triangle at top of column)
  • Select text filters
  • Select Does not contain
  • Enter type
  • Modify and rerun as needed.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top