如何检查单元格的值是否是另一个单元格的子值

我有两个列和ID,如“TCG45436”在他们两个。 第一列包括“TCG45436(5)”括号中的数字。 我需要检查两列以查看ID是否匹配,并清除第二列中的单元格内容。 问题是如果第一列包含(5),那么两者不匹配,但是我只需要ID本身在两列中匹配。 在过去,我使用子string来做类似的事情,以查找列2是否是第一列的子string,但我不知道如何在这里应用。

本质上,我想要B30和B32-B37在这个片段中清除。

Excel ScreenShot http://img526.imageshack.us/img526/7646/24288154.png

Sub TwoColumns() Do Until ActiveCell.Value = "" Column1 = ActiveCell.Value Column2 = ActiveCell.Offset(0, 1).Value If Column1 = Column2 Then 'needs to be If Column2 is equal to or a subvalue of Column1 Else ActiveCell.Offset(0, 1).ClearContents End If ActiveCell.Offset(1, 0).Select Loop End Sub 

谢谢

你可能想要使用InStr函数:

 If InStr(0, Column1.Value, Column2.Value) <> 0 Then 'it's a substring.