vb.net。确切的匹配

时间:2014-08-19 02:51:02

标签: vb.net

你好我试图在excel中找到一个字符串的完全匹配而不是它的一部分,单元格必须等于确切的字符串而不仅仅是它的一部分就是我得到的。

Private Sub txtSMaterial_Leave(sender As Object, e As EventArgs) Handles txtSMaterial.Leave
    strEX = txtSMaterial.Text.ToString()
   Found = oSheetExtrusions.Range("A6:A5000").Find(What:=strEX, _
                                                        LookIn:=Excel.XlFindLookIn.xlValues, _
                                                        LookAt:=Excel.XlLookAt.xlWhole, _
                                                        SearchOrder:=Excel.XlSearchOrder.xlByRows, _
                                                        SearchDirection:=Excel.XlSearchDirection.xlNext)

    If Found Is Nothing Then
        txtSLength.Text = "N/A"
        Exit Sub
    Else

    End If

    txtSLength.Text = strExLength

End Sub

1 个答案:

答案 0 :(得分:1)

您需要添加参数以查看xlWhole。见下面的搜索功能

Dim aCell As Range
Dim lastRow As Long
Dim oSht As Worksheet
Dim searchString As String
//Set to your sheet name
Set oSht = Sheets("Sheet1")
//Set to your search parameter
searchString = "101010101"
Set aCell = oSht.Range("A1:A" & lastRow).Find(What:=searchString, LookIn:=xlValues, LookAt:=xlWhole,       SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)