Excel VBA - 单元格值包含“MIG”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12365123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 17:40:48  来源:igfitidea点击:

Excel VBA - Cell value contains 'MIG'

excelexcel-vbavba

提问by CustomX

I know theres a way to look if a cell value contains a certain string. I know some programming languages use % ... %.

我知道有一种方法可以查看单元格值是否包含某个字符串。我知道一些编程语言使用 % ... %。

    If shtVO.Cells(Row, 1).Value <> "%MIG%" Then
        shtVO.Cells(Row, 1).Value = shtVO.Cells(Row, 1).Value + "MIG"
    End If

I want to see if my Cell A already contains MIG, if it does it shouldn't update the value, if it doesn't contain MIG, it should update the current value with MIG.

我想看看我的 Cell A 是否已经包含 MIG,如果包含它不应该更新值,如果它不包含 MIG,它应该使用 MIG 更新当前值。

回答by chris neilsen

Try this

尝试这个

If not shtVO.Cells(Row, 1).Value like "*MIG*" Then

回答by Passerby

If InStr(0, shtVO.Cells(Row, 1).Value, "MIG", vbTextCompare)=0 Then
    shtVO.Cells(Row, 1).Value = shtVO.Cells(Row, 1).Value + "MIG"
End If