我在 VBA for excel 中有下一个代码的第一个版本
Function findCell(celda As String, rnc As String) As String
Dim cell As Range
Dim pos As String
Range("A2").Select
Set cell = Cells.Find(What:=celda, After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False)
If cell Is Nothing Then
pos = 0
Else
pos = cell.row
End If
findCell = pos
End Function
该函数接收一个字符串并返回列数中的位置,但是在我更改参数之后,因为我必须找到单元格的完整包含。我将值 lookAt 从x1Part更改为x1Whole
Set cell = Cells.Find(What:=celda, After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False)
当我尝试运行宏有时不起作用并向我显示该值x1Whole,但是当我从编辑器运行时。