Cells.Find() 引发“运行时错误 91:对象变量或块未设置" [英] Cells.Find() Raises "Runtime Error 91: Object Variable or With Block Not Set"

查看:45
本文介绍了Cells.Find() 引发“运行时错误 91:对象变量或块未设置"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的:我有很多带有不同设备的床单.我们将其中一张表称为WS1".

What I want: I've got a lot of sheets whith different devices. Let's call one of these sheets "WS1".

我有一张单独的表格,其中包含所有现有设备和旁边的相应操作系统.我们称之为列表".

And I've got a seperate sheet with all existing devices and the appropriate OS next to it. This one we call "list".

现在我希望其他工作表(例如WS1")检查列表",找到正确的设备,并将正确的操作系统复制到 WS1 工作表中.

Now I want the other sheets (e.g. the "WS1") to check the "list", find the right device, and copy the right OS into the WS1-sheet.

手动方式是:

  • 选择 WS1 的单元格C3"并复制它.
  • 打开列表"-工作表并找到复制的条目
  • 选择找到的条目左侧的单元格并复制它
  • 再次打开 WS1,选择活动单元格右侧的左侧单元格并粘贴新的剪贴板(其中包含操作系统)
  • 选择活动单元格下方和右侧的下一个单元格.
  • 循环直到 WS1 中的每个设备都装满了一个操作系统

到目前为止我所拥有的:

Dim DataObj As New MSForms.DataObject
Dim strCliBoa As String
'strCliBoa = DataObj.GetText
DataObj.GetFromClipboard

Range("C3").Select
Selection.Copy
strCliBoa = DataObj.GetText
Sheets("list").Select
Range("A1").Select
Cells.Find(What:=strCliBoa, After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=True, SearchFormat:=False).Activate
ActiveCell.Offset(0, -1).Select
Selection.Copy
strCliBoa = DataObj.GetText
Sheets("WS1").Select
ActiveCell.Offset(0, -1).Select
ActiveSheet.Paste
ActiveCell.Offset(1, 1).Select

我的问题:运行时错误 91:对象变量或块变量未设置"它标记了cells.find-method.

My issue: "Runtime Error 91: Object variable or with block variable not set" and it marks the cells.find-method.

谁能告诉我我做错了什么?^^提前致谢!

Can someone tell me what I'm doing wrong?^^ Thanks in advance!

(哦,差点忘了:我在 Win7 上使用的是 ms excel 2010)

(oh, almost forgot: I'm using ms excel 2010 on Win7)

推荐答案

如果未找到您要查找的字符串,您将收到该错误.如果没有找到,则 find 函数返回Nothing"

If the string you're looking for isn't found you'll get that error. The find function returns "Nothing" if nothing is found

    Dim r As Range

    Set r = Cells.find(What:=strCliBoa, After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=True, SearchFormat:=False)

    If r Is Nothing Then
        'handle error
    Else
        'fill in your code
    End If

这篇关于Cells.Find() 引发“运行时错误 91:对象变量或块未设置"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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