[英]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 是可取的,因为它可以检查单元格而不会像VLookup或Match那样抛出错误。
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*"))
将返回True
或False
具体取决于单元格中是否包含“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.