简体   繁体   English

检查工作表(多张工作表)中是否存在值并返回“条目已存在”-Excel

[英]Check if a value exists in a Worksheet (multiple sheets) and return “Entry already exists” - Excel

I have an excel file with multiple sheets with row entries, where each entry has multiple columns with different information. 我有一个带有多个带有行条目的工作表的excel文件,其中每个条目都有多个具有不同信息的列。 What I want to do is, every time I enter a new entry, check if it already exists in another sheet (of the same file). 我想做的是,每当我输入一个新条目时,检查它是否已存在于另一个表(同一文件)中。 That is to check if a row in the file contains the same information and have a return like "Entry already exists" or FALSE or anything to let me know so that I don't have the same entry twice in the file. 那是为了检查文件中的行是否包含相同的信息,并返回诸如“ Entry has exist”或FALSE之类的信息,或者让我知道的东西,以使我在文件中没有两次相同的条目。

I have no idea how to even begin (or even if that is possible). 我什至不知道如何开始(或者即使有可能)。 Can anyone help? 有人可以帮忙吗?

ps. ps。 Sorry if my question is too complicated, I couldn't find a better way to put it into words. 抱歉,如果我的问题太复杂了,我找不到更好的方法将其写成文字。

If your data is in one column or one row, by faaar the easiest method is to use conditional formatting; 如果您的数据是在一列或一行中,那么最简单的方法是使用条件格式。 Conditional Formatting -> Highlight cells rules -> Duplicate values. 条件格式->高亮显示单元格规则->重复值。

If you want to check across different sheets or different columns, use MATCH function. 如果要检查不同的工作表或不同的列,请使用MATCH功能。 MATCH returns the relative location of a string in an array. MATCH返回字符串在数组中的相对位置。 I'd see it working something like... 我会看到它像...

=MATCH(NewEntry,ArrayWhereItCouldAppear,0)

If you put in entry "x" in row, let's say, 102 (eg address is "B102"), but you already have entry "x" in row 15 (eg address is "B15"), then MATCH would be returning "15". 如果您在行中输入条目“ x”,例如102(例如地址为“ B102”),但在行15中已经有条目“ x”(例如地址为“ B15”),那么MATCH将返回“ 15“。

In order to automatize it, you'd need to OFFSET to provide the last row's reference (I assume you are adding new rows). 为了使其自动化,您需要进行OFFSET操作以提供最后一行的引用(假设您要添加新行)。 Use something like... 使用类似...

=OFFSET(B1, COUNTA(B:B)-1, 0)

as your NewEntry. 作为您的NewEntry。 Offset in essence "moves" your range based on the criteria; 偏移实质上是根据条件“移动”您的范围; the above instructs it to return whatever is found in COUNTA(B:B)-1 rows under the cell B1. 上面的命令指示它返回在单元格B1下的COUNTA(B:B)-1行中找到的任何内容。 COUNTA counts non-empty cells, and the -1 accounts for the (likely) header of your table. COUNTA计算非空单元格,而-1代表表的(可能)标头。 Thus, if you were adding "x" in row 102, the function would return your "x". 因此,如果要在第102行中添加“ x”,则该函数将返回“ x”。

Lastly, you have mentioned you would like to see TRUE or FALSE appear. 最后,您提到过您希望看到TRUE或FALSE。 The easiest check is to do a boolean check if MATCH returns anything greater than zero. 最简单的检查是如果MATCH返回的值大于零,则进行布尔检查。 However, MATCH won't return zero if it doesn't find an entry; 但是,MATCH如果找不到条目,​​则不会返回零; it will return an error. 它将返回一个错误。 Therefore, we need to wrap our formula in IFERROR. 因此,我们需要将公式包装在IFERROR中。 We thus end with something like... 因此,我们以类似...的结尾

=IFERROR(MATCH(OFFSET(ColumnWhereUniqueIDIs:1,COUNTA(ColumnWhereUniqueIDIs:ColumnWhereUniqueIDIs)-1,0),ArrayWhereItCouldAppear,0),0)>0 = IFERROR(MATCH(OFFSET(ColumnWhereUniqueIDIs:1,COUNTA(ColumnWhereUniqueIDIs:ColumnWhereUniqueIDIs)-1,0),ArrayWhereItCouldAppear,0),0)> 0

This is cool, because you can plug in ANY array where the "x" might appear. 这很酷,因为您可以插入可能出现“ x”的任何数组。 You can do this across multiple sheets (simply adding the formulas, as in "check this array" + "check this array" + ...). 您可以跨多个工作表执行此操作(只需添加公式即可,例如“检查此数组” +“检查此数组” + ...)。

I hope this helps. 我希望这有帮助。 If anyone can come up with an easier solution, please do! 如果有人可以提出更简单的解决方案,请执行!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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