检查一个单元格是否包含与另一个单元格VBA相同的EXACT数据 [英] Check if one cell contains the EXACT same data as another cell VBA

查看:505
本文介绍了检查一个单元格是否包含与另一个单元格VBA相同的EXACT数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  BC(列)
1 1a(第1行在这里)
2 3
3 4
4 4a
4a 5
5 5a
5a 6
6 6a
6a 6b
6b 10
10 11
11 12
12 13
13 14
14 15
15 16
16 16a
16a 16b
16b 16c
16c OUT
7 7a
7a 8
8 9
9 6

我想说如果单元格B7中的数据等于输入单元格O7的完全相同的数据,那么执行语句。如果没有,请转到下一个单元格并检索该值,然后[执行其他语句]



我尝试过的问题是即使单元格中有一个4,我想要从4a开始找到单元格,它仍然以包含4的单元格开头,因为在4a中有一个4



示例:

 对于x = 7 
如果表格(Sheet3) .Cells(X,值为
[执行语句]

如果O7被设置为等于4a,它将在B中查找第一个值为4,而不是4a



有没有一个特殊的功能或命令使我的代码找到确切的值,而不只是第一个单元格的一部分值?



谢谢。

解决方案

尝试使用 Strcomp()



如果StrComp(Sheets(Sheet3)。Cells x,2).Value,Sheets(Sheet3)。Cells(7,O)。Value)= 0 Then ...



当StrComp为0时,表示完全匹配。


I have an Excel Sheet with Column A and a Column B filled with data.

B    C       (columns)
1   1a       (row 1 is here)
2   3
3   4
4   4a
4a  5
5   5a
5a  6
6   6a
6a  6b
6b  10
10  11
11  12
12  13
13  14
14  15
15  16
16  16a
16a 16b
16b 16c
16c OUT
7   7a
7a  8
8   9
9   6

I want to say "If data in cell B7 equals the exact same data entered into cell O7, then execute statement. If it doesn't, go to next cell and retrieve that value, then [perform other statements]"

The problem with what I have tried, is that even if a cell has a "4" in it and I want to find the the cell starting with exactly "4a," it still starts with the cell that contains just "4" because there is a 4 in "4a"

Example:

For x = 7 
    If Sheets("Sheet3").Cells(x, 2).Value = Sheets("Sheet3").Cells(7, "O").Value
        [execute statement]

If "O7" is set equal to "4a", it looks up the first value in B with a "4" in it instead of exactly "4a"

Is there a special function or command to make my code find the exact value and not just the first cell with part of the value in it?

Thank you.

解决方案

Try using Strcomp()

If StrComp (Sheets("Sheet3").Cells(x,2).Value,Sheets("Sheet3").Cells(7,"O").Value) = 0 Then ...

When StrComp is 0, it means an exact match.

这篇关于检查一个单元格是否包含与另一个单元格VBA相同的EXACT数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆