VBA For循环IF Instr没有找到子串

时间:2017-10-12 18:11:29

标签: excel vba excel-vba for-loop if-statement

下午,

D2中的单元格包含" CH-SFDC-ENH-XXX-ALM-中国法律案例增强" 该公式正在寻找子串" -SFDC - "它包含在单元格中,并将为指定的单元格HX分配值。运行时,它找不到子字符串并指定值unknown。

以下是公式。我错过了什么?

lastrow = Worksheets("SFDC").UsedRange.Rows.Count
Set Check = Range("D2:D" & lastrow)
cellvalue = 2

For Each cell In Check

       'I have also tried "SFDC"
    If InStr(cell, "*-SFDC-*") Then
        Cells(cellvalue, "H") = "SFDC"

    ElseIf InStr(cell, "*-FE-*") Then
        Cells(cellvalue, "H") = "FE"

    Else
        Cells(cellvalue, "H") = "Unknown"

    End If
    cellvalue = cellvalue + 1
Next

EDIT解决了两个问题

If InStr(cell, "-SFDC-") Then
or
If cell.Value Like "*-SFDC-*" Then

0 个答案:

没有答案