VBA .range.find错误"未设置块变量"

时间:2017-05-07 22:09:31

标签: excel vba

我似乎无法看到问题在这里。

我试过了:

Dim findRow As Integer
Dim findRow As Range
Dim findRow As Excel.Range

他们都给出了同样的错误。 我试过.with和没有.width

这是我的代码:

Dim findRow As Excel.Range

findRow = ActiveWorkbook.Worksheets("AllAgents").Range("F:F").Find(What:=strEmail(1), LookIn:=xlValues)

With ActiveWorkbook.Worksheets("AllAgents")
    MsgBox (.Cells(2, 6))
    findRow = .Range("F:F").Find(What:=strEmail(1), LookIn:=xlValues)
End With

MsgBox显示正确的值,因此它就在那里。

这是我得到的错误:enter image description here

enter image description here

1 个答案:

答案 0 :(得分:4)

Set findRow = ... - 您正在分配一个对象变量,因此需要Set