我试图在列表中找到一个 id 并获取它的地址,但如果没有找到,也要处理一种情况。
这是我所拥有的:
Function find_in_two_ranges_two_sheets(ws1 As String, col1 As Integer) As Range
Dim rows1 As Integer
rows1 = Get_Rows_Generic(ws1, 1)
Dim range1 As Range ' range of first search
With Worksheets(ws1)
Set range1 = .Range(.Cells(1, col1), .Cells(rows1, col1))
End With
Dim found1 As Range
Set found1 = range1.Find("test id", LookIn:=xlValues)
If found1 = Nothing Then
MsgBox "nothing"
Else
MsgBox found1.AddressLocal
End If
Set find_in_two_ranges_two_sheets = range1
End Function
Sub test_stuff()
Dim x As Range
Set x = find_in_two_ranges_two_sheets("usersFullOutput.csv", 1)
MsgBox x.Address
End Sub
当我运行时,在突出显示单词test_stuff()
的行中的函数中出现错误。“编译错误;对象的无效使用”。不知道该怎么办。If found1 = Nothing Then
Nothing