我偶然发现了这个有用的 VBA 函数:Find a row from Excel table using VBA
Function GetRow(TableName As String, ColumnNum As Long, Key As Variant) As Range
On Error Resume Next
Set GetRow = Range(TableName) _
.Rows(WorksheetFunction.Match(Key, Range(TableName).Columns(ColumnNum), 0))
If Err.Number <> 0 Then
Err.Clear
Set GetRow = Nothing
End If
End Function
此功能非常适用于文本。但是,我在搜索数字时遇到了严重的问题。搜索整数时,我永远不会返回一行。
我正在使用这样的功能:
If Not Userform_Input.Text = "" Then
Set ref = GetRow("table", 3, Userform_Input.Text)
If Not ref Is Nothing Then
variable_a = Cells(ref.Row, 2).value
End If
End If
看代码我看不出问题。还有人吗?