我正在尝试使用执行do while循环。FindNext方法在一列中查找多个实例。就其本身而言,它运行良好。
然而当试图在同一循环内的另一张表中找到相应值时,它抛出“Object variable or With block variable not set”(对象变量或未设置块变量)错误(91)。
If Not found_title Is Nothing Then
first_cell_address = found_title.Address
Do
Set found_url = url_lookup.Find(found_title.Offset(0, -4).Value)
Debug.Print ("looped")
Set found_title = title_lookup.FindNext(found_title)
Loop While first_cell_address <> found_title.Address
End If
当我注释掉“set found\u url…”它工作正常,但当包含它时,“found\u title”对象在第一次达到while条件时已设置为nothing。由于FindNext方法围绕着范围,我不明白为什么在必须至少有一个方法才能首先输入if语句的情况下将其设置为nothing。
解决方案:
根据rory的回复,变化是:
Set found_title = title_lookup.Find(title, After:=Range(found_title.Address))