Trouble with vba error 91 when using With, Range and .Find

这一生的挚爱 提交于 2020-01-06 07:14:34

问题


i would like to find the address of the cell containing the value "USD" in below mentioned code. though, the system throws me an error 91 saying that an object variable has not been set. i found some info online on error 91 but i still don't get where and how to set the right object. help is appreciated.

thanks

Sub searchAdress()
 Dim searchAdress As Range
 With Workbooks("Umrechnungskurse1.xlsm").Sheets("Tabelle1").Range("A2:S2")
    searchAdress = .Find("USD", LookIn:=xlValues)
 End With
 MsgBox searchAdress
End Sub

回答1:


The first problem is that your line:
searchAdress = .Find("USD", LookIn:=xlValues)

Should be :
Set searchAdress = .Find("USD", LookIn:=xlValues)
The Set command is required for object variables.

Your next problem is that your MsgBox will not work. Change the line to:
MsgBox searchAdress.Address



来源:https://stackoverflow.com/questions/26784347/trouble-with-vba-error-91-when-using-with-range-and-find

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!