【问题标题】:Partial cell match and disregarding punctuation VBA部分单元格匹配和忽略标点符号 VBA
【发布时间】:2016-05-13 15:50:17
【问题描述】:

这是来自Partial Cell Match 的扩展问题。

如果名称中有标点符号,我想知道如何进一步改进 John Coleman 提供的以下编码,

Name1 的一个示例是“IT 主管 Sally, Lim”

Name2 的一个例子是“Sally, Lim”

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

【问题讨论】:

    标签: vba excel punctuation


    【解决方案1】:

    使用函数来“整理”字符串:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-02
      • 1970-01-01
      • 2018-03-11
      • 2019-07-29
      相关资源
      最近更新 更多