Vb.net 测试完整的VB代码,以查找包含代码中指定的值(精确匹配)的单元格

Vb.net 测试完整的VB代码,以查找包含代码中指定的值(精确匹配)的单元格,vb.net,excel,search,match,testcomplete,Vb.net,Excel,Search,Match,Testcomplete,我有TestComplete VB代码,它返回excel文件中的单元格,该文件包含代码中指定的值 问题是excel中代码搜索的单词与代码中指定的值不完全匹配 在vba中,将“xlPart”替换为“xlother”可以解决我的问题 我只想返回与整个单元格内容匹配的单元格 我使用的代码 Function FindCell(sheet, searchRange, Value, returnWhat) Dim CellPosition, c, Search_In If searchRange

我有TestComplete VB代码,它返回excel文件中的单元格,该文件包含代码中指定的值

问题是excel中代码搜索的单词与代码中指定的值不完全匹配

在vba中,将“xlPart”替换为“xlother”可以解决我的问题

我只想返回与整个单元格内容匹配的单元格

我使用的代码

Function FindCell(sheet, searchRange, Value, returnWhat)

 Dim CellPosition, c, Search_In


 If searchRange = "Entire_Sheet" then
    Set Search_In = sheet.Cells
 else
     Set Search_In = sheet.Range(searchRange)
 End If


  With Search_In
     Set c = .Find(Value)
     If Not c Is Nothing Then

         if returnWhat = "Row_Number" then
           CellPosition = c.row
         elseif returnWhat = "Column_Number" then
           CellPosition = c.column 
         end if

     End If
  End With

  FindCell = CellPosition

End Function

我应该在这里编辑什么以获得解决方案

此代码在VBA中工作不了解VB

Function FindCell(sheet As Worksheet, searchRange As String, Valuee As Variant, returnWhat As String) As Long
 Dim CellPosition, c, Search_In, r
 CellPosition = -9999
 If searchRange = "Entire_Sheet" Then
    Set Search_In = sheet.Cells
 Else
     Set Search_In = sheet.Range(searchRange)
 End If
  With Search_In
     Set c = Nothing
     For Each r In Search_In
        If r.Value = Valuee Then
            Set c = r
        End If
     Next
     If Not c Is Nothing Then
         If returnWhat = "Row_Number" Then
           CellPosition = c.Row
         Else
           CellPosition = c.Column
         End If
     End If
  End With
  FindCell = CellPosition
End Function

下面的代码解决了我查找包含与我搜索的值完全匹配的单元格的问题

Function FindCell(sheet, searchRange, Value, returnWhat)

 Dim CellPosition, c, Search_In
 Dim i, CellArray()


 If searchRange = "Entire_Sheet" then
    Set Search_In = sheet.Cells
 else
     Set Search_In = sheet.Range(searchRange)
 End If


 With Search_In
   Set c = .Find(Value)
   i = 0
   If Not c Is Nothing Then
      firstAddress = c.Address
      Do
        ReDim Preserve CellArray(i)
        CellArray(i) = ColumnLetter(c.column) & c.row
        if c = Value then
           if returnWhat = "Row_Number" then
               CellPosition = c.row
           elseif  returnWhat = "Column_Number" then
              CellPosition = c.column
           End if
        'Log.Message("The Jing value is found in " & CellArray(i))
        Exit Do
        End if
        i = i + 1
       Set c = .FindNext(c)
      Loop While Not c Is Nothing And c.Address <> firstAddress
    End If
 End With

  FindCell = CellPosition

End Function
函数FindCell(表、搜索范围、值、返回内容)
调暗单元格位置,c,搜索
迪姆一,雷()
如果searchRange=“整个工作表”,则
设置Search_In=sheet.Cells
其他的
设置搜索范围=工作表范围(搜索范围)
如果结束
随着搜索的深入
设置c=.Find(值)
i=0
如果不是,那么c什么都不是
firstAddress=c.地址
做
雷迪姆射线(一)
X射线(i)=列字母(c列)和c行
如果c=值,则
如果returnWhat=“行号”,则
CellPosition=c行
elseif returnWhat=“列号”然后
CellPosition=c列
如果结束
'Log.Message(“Jing值在“&i”)中找到)
退出Do
如果结束
i=i+1
集合c=.FindNext(c)
循环而不是c为Nothing,c.Address为firstAddress
如果结束
以
FindCell=CellPosition
端函数

No在TestComplete中,它与vb脚本不兼容。对于搜索中的每个r\u,我收到一个VBScript运行时错误“行中的对象不是集合”