Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 比较两个单元格中的数据以查找部分匹配_Excel_Vba - Fatal编程技术网

Excel 比较两个单元格中的数据以查找部分匹配

Excel 比较两个单元格中的数据以查找部分匹配,excel,vba,Excel,Vba,这可能是一个非常简单的脚本,但我的编码很糟糕 我有一列带有姓氏列表,B列带有文件名,文件名应该在字符串中的某个位置包含姓氏 i、 e 我需要检查A列中姓氏的拼写是否在B列的字符串中找到,并突出显示不匹配的行 在本例中,托马斯的第三行将突出显示 要检查的行不应超过1000行 我在任何地方都找不到一段代码可以帮我做到这一点 谢谢你能提供的任何帮助 dim numrows as long numrows = Cells.find("*", [A1], , , xlByRows, xlPrevious)

这可能是一个非常简单的脚本,但我的编码很糟糕

我有一列带有姓氏列表,B列带有文件名,文件名应该在字符串中的某个位置包含姓氏

i、 e

我需要检查A列中姓氏的拼写是否在B列的字符串中找到,并突出显示不匹配的行

在本例中,托马斯的第三行将突出显示

要检查的行不应超过1000行

我在任何地方都找不到一段代码可以帮我做到这一点

谢谢你能提供的任何帮助

dim numrows as long
numrows = Cells.find("*", [A1], , , xlByRows, xlPrevious).Row


'loop over all rows
for i = 1 to numrows
    'instr function returns 0 if string 2 is not found within string 1. in this case, if the value in col A, is not found within col B
    if instr(1, cells(i,2).formulaR1C1, Cells(i,1).formulaR1C1) = 0 then
        Cells(i,1).entireRow.interior.color = RGB(255,255,0) 'highlight row
    end if
next
欢迎来到这里,你是对的,很简单。但是请注意,根据“关于主题答案”的帮助页面,“询问代码的问题必须表明对正在解决的问题的最低理解。包括尝试的解决方案、为什么它们不起作用以及预期的结果。”请在以后的帖子中牢记这一点:)

另外,如果这对您有效,请不要忘记标记为答案:)

dim numrows as long
numrows = Cells.find("*", [A1], , , xlByRows, xlPrevious).Row


'loop over all rows
for i = 1 to numrows
    'instr function returns 0 if string 2 is not found within string 1. in this case, if the value in col A, is not found within col B
    if instr(1, cells(i,2).formulaR1C1, Cells(i,1).formulaR1C1) = 0 then
        Cells(i,1).entireRow.interior.color = RGB(255,255,0) 'highlight row
    end if
next