查找命令给出错误:“运行时错误”91':对象变量或未设置块变量“ [英] Find command giving error: "Run-time Error '91': Object variable or With block variable not set"

查看:123
本文介绍了查找命令给出错误:“运行时错误”91':对象变量或未设置块变量“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试激活我的列A中的生成器加载的单元格。



我一直在尝试发布在网上的'With'和'End With'命令和其他建议的格式。但是,我不断得到相同的错误 - 运行时错误91.



从我的各种试验我非常确定在查找命令中有错误,但是我无法弄清楚我在使用MSDN页面上的格式填写了什么。



你有什么建议吗?

$ b $



表格(摘要)列(1) Find(What:= findstring,After:= Cells(9,1))。激活


解决方案

如果 .Find 方法的结果为 Nothing ,则通常会出现此错误,因为你不能做 Nothing.Activate



首先,你必须检查 Nothingness

  Dim rng as Range 
Set rng = Sheets(Summary)。列(1).Find (What:= findstring,After:= Cells(9,1))

如果rng不是,然后
MsgBox findString& 没找到!!,vbCritical
退出Sub
结束如果

rng.Activate

'其余的代码到这里...


Trying to activate the cell in my column A which says "Generator loading".

I have been trying the 'With' and 'End With' commands and other suggested formats posted on the net. However, I keep getting the same error- Run-time Error 91.

From my various trials I am very sure that there is something wrong within the "Find" command, but I cannot figure out what... I have been filling it using the format on the MSDN page.

Do you have any suggestions?

Dim findstring As String
findstring = "Generator loading"

Sheets("Summary").Columns(1).Find(What:=findstring, After:=Cells(9,1)).Activate

解决方案

The error commonly arises if the result of the .Find method is Nothing, because you can't do Nothing.Activate

First, you have to check for Nothingness

Dim rng as Range
Set rng = Sheets("Summary").Columns(1).Find(What:=findstring, After:=Cells(9,1))

If rng Is Nothing Then
    MsgBox findString & " not found!!", vbCritical
    Exit Sub
End If

rng.Activate

'the rest of your code goes here...

这篇关于查找命令给出错误:“运行时错误”91':对象变量或未设置块变量“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆