简体   繁体   English

如何检查列中的一系列字符串是否包含在另一个工作表的另一列中?

[英]How to check if a a range of strings in a column, are contained in another column in another worksheet?

I would like to check a range of strings using a macro我想使用宏检查一系列字符串

(example of strings: string sometimes contains numbers: VNVININT2HAI, BRKARLTD999FRA) (字符串示例:字符串有时包含数字:VNVININT2HAI、BRKARLTD999FRA)

in a column (H3:H100) in Sheet1 and if it exists in a column(K2:K100) in Sheet2在 Sheet1 的列 (H3:H100) 中,如果它存在于 Sheet2 的列 (K2:K100) 中

then mark the cells in Sheet1 either green if the string matches up with any of the strings in the column in Sheet2.如果字符串与 Sheet2 中列中的任何字符串匹配,则将 Sheet1 中的单元格标记为绿色。 Then Mark the Cells in Sheet1 either green if it matches or red if it doesnt.然后将 Sheet1 中的单元格标记为绿色(如果匹配)或红色(如果不匹配)。

I've googled for answers found mostly code for integers, and formulas using Vlookup, not the exact answer I was looking for.我用谷歌搜索了答案,发现主要是整数代码和使用 Vlookup 的公式,而不是我正在寻找的确切答案。

You have multiple questions.您有多个问题。 However I'll answer part of it by saying COUNTIF is an underrated tool for CHECKING if something exists or not.但是,我将通过说COUNTIF是一个被低估的工具来回答它的一部分,用于检查是否存在某些东西。 Countif is desirable because it can check cells without throwing errors as VLookup or Match might. Countif 是可取的,因为它可以检查单元格而不会像VLookupMatch那样抛出错误。

Example for checking if value exists in a range could be written like this in excel =OR(COUNTIF(E:E,"VNVININT2HAI")) which would return True if any cell had a value of your text.检查范围中是否存在值的示例可以像这样写在 excel =OR(COUNTIF(E:E,"VNVININT2HAI")) ,如果任何单元格具有文本值,它将返回True

You can also use it to check if a cell contains it by using * for the sides.您还可以使用它来检查单元格是否包含它,方法是在两侧使用 *。

Example: =OR(COUNTIF(E6,"*2*")) would return True or False depending if a cell contains a "2" anywhere in it.示例: =OR(COUNTIF(E6,"*2*"))将返回TrueFalse具体取决于单元格中是否包含“2”。

I doubt this fully answers your question, but for people looking on how to "check cells and ranges" COUNTIF is probably more useful than you think.我怀疑这是否完全回答了您的问题,但对于寻找如何“检查单元格和范围”的人来说, COUNTIF可能比您想象的更有用。 It's applicable in VBA too (sometimes I prefer it over instr).它也适用于 VBA(有时我更喜欢它而不是instr)。

EDIT This works, but if you have a LOT of cells to check, perhaps consider using IsNumber(Match() as shown in comments by @scottCraner编辑这有效,但如果你有很多单元格要检查,也许可以考虑使用IsNumber(Match() ,如@scottCraner 的评论中所示

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

相关问题 VBA:如何用字符串连接一列中的单元格范围并在另一列中生成它? - VBA: How to concatenate range of cells in a column with strings and generate it in another column? 用于检查范围是否包含在另一个范围内的功能 - Function to check if a range is contained in another Excel-检查值是否存在于另一个工作表的列中并返回相邻列 - Excel - Check if value exists in a column in another worksheet and return adjacent column 对两列执行检查,逐列复制另一个工作表 - Perform check on two columns, Copy column by column another Worksheet 将一列中的值复制到另一个工作表中的另一列 - Copying values in a column to another column in another worksheet 根据范围中的日期更新来自另一个工作表的列中的值 - Update value in a column from another worksheet depending on the date in a range 将具有NULL列的数据行复制到同一工作表中的另一个范围 - copy data rows with NULL column to another range in the same worksheet 将另一个工作表中的列的总和相加 - Sum the total of a column in another worksheet 将多列从一个工作表复制到另一工作表的一列 - copy multiple column from one worksheet to one column in another worksheet 将一个工作表中的列中的单元格转换为另一工作表中的列标题 - Converting cells in a column in one worksheet as column headers in another worksheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM