2016-05-13 64 views
1

这是从Partial Cell Match扩展的问题。部分单元格匹配和无视标点符号VBA

我想知道我怎么可以进一步改善以下的编码由约翰·科尔曼提供,如果有标点符号的名义,

名1的一个例子是“IT经理萨莉,廉”

的例子名称2将是 “莎莉,廉”

Name1 = Sheets("Work").Cells(RowName1, ColName1) 
Name2 = Sheets("Roster").Cells(RowName2, ColName2) 

If UCase(Trim(Name1)) Like "*" & UCase(Trim(Name2)) & "*" then 
    Name2.Font.Strikethrough = True 
    End If 

回答

2

使用的功能, “整洁” 了绳子:

Function ReplacePunct(strInput As String) As String 

chars = Array(".", ",", ";", ":") '// Change as required 

    For Each ch In chars 
     While InStr(strInput) 
      strInput = Replace(strInput, CStr(ch), vbNullString) 
     Wend 
    End If 

End Function 

然后像这样使用它:

If UCase(Trim(ReplacePunct(Name1))) Like "*" & UCase(Trim(ReplacePunct(Name2))) & "*" then 
相关问题