Cells.Find()引发“运行时错误91:对象变量或块未设置” [英] Cells.Find() Raises "Runtime Error 91: Object Variable or With Block Not Set"
问题描述
我想要的:
我有不同的设备有很多张。我们来打电话给其中一个表格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,选择活动单元格旁边的左侧单元格,然后粘贴新的剪贴板(包含OS)
- 选择活动单元格右下方的下一个单元格。
- 循环,直到WS1中的每个设备都填充一个操作系统
- select cell "C3" of WS1 and copy it.
- open the "list"-Sheet and find the copied entry
- select the cell left to the found entry and copy it
- open the WS1 again, select the left cell right next to the active cell and paste the new clipboard (which contains the OS)
- select the next cell which is under and on the right side of the active cell.
- loop until every device in WS1 is filled with an OS
到目前为止我已经有了
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方法。
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屋!