VBA匹配问题

时间:2016-04-22 01:36:01

标签: excel vba excel-vba

以下代码用于在两张纸之间进行匹配。 它工作正常,但在

时有问题

例如在表1中:(注意:我使用表1中的内容在表2中进行匹配)

Cells(1, 8) value: Rev#

Cells(1, 3) value: REV#

在表2中:

Value for Rev#: 123xyz

Value for REV#: PQRSABC

Rev#和REV#完全不同,但我从程序中得到的结果总是“123xyz”。我们是否有任何想法得到正确的结果,而不是将Rename REV#重命名为其他?

感谢您的建议。

icol = 1

For icol = 1 To numofcol
    FindString = Worksheets("Temp_A").Cells(1, icol).Value
    Set rng = ActiveSheet.Range(Cells(1, 1), Cells(numofrow1, numofcol1)).Find(what:=FindString, LookIn:=xlValues, LookAt:=xlWhole)

    If rng.Value = "Process Type:" Then
        If InStr(rng.Offset(-1, 0).Resize(1, 1).Value, ":") > 0 Then
            temp = vbNullString
        Else
            temp = rng.Offset(-1, 0).Resize(1, 1).Value
        End If
    Else
        If InStr(rng.Offset(1, 0).Resize(1, 1).Value, ":") > 0 Then
            temp = vbNullString
        Else
            temp = rng.Offset(1, 0).Resize(1, 1).Value
        End If
    End If

0 个答案:

没有答案