我编写了一个函数来查找在特定范围内具有特定值的单元格。但是我一直在线上遇到“ object required”错误:如果rng为空。
如果我将函数参数(搜索值)类型设置为字符串,则不会发生此错误,仅当函数参数(搜索值)类型为变量时才会发生。
这是我的代码:
Function TgtCell(SearchRange As Range, Optional SearchValue As Variant) As Range
For Each Rng In SearchRange
If IsMissing(SearchValue) Then
If Rng Is Empty Then 'this is the line with the error
TgtCell = Rng
Exit For
End If
Else
If Rng.Value = SearchValue Then
Set TgtCell = Rng
Exit For
End If
End If
Next
End Function
下面是我的测试代码:
Sub test1()
Set Rng = TgtCell(Range([a1:a14], Cells(Rows.Count, 1)))
Rng.Select
End Sub
请帮助我了解为什么会这样。
答案 0 :(得分:0)
如果要检查单元格/范围是否为“空”,请使用IsEmpty。
const mapDispatchToProps = dispatch => ({
incrementCounter: () => dispatch(incrementCounter()),
createCounter: () => dispatch(createCounter())
});