Vba 使用Range.find时出现运行时错误91
解决了Nathan_SAV的想法是对的。对于以后查看此代码以供参考的任何人,我将代码更改为Vba 使用Range.find时出现运行时错误91,vba,excel,Vba,Excel,解决了Nathan_SAV的想法是对的。对于以后查看此代码以供参考的任何人,我将代码更改为 For x = 3 To lRow On Error Resume Next 'If then Find statement If Err.Number <> 0 Then '.... End If x=3至lRow的 出错时继续下一步 'If then Find语句 如果错误号为0,则 '.... 如果结束 我还是VBA新手,遇到了一个错误,我不知道如何修复它 我收到“运行时错误'91'
For x = 3 To lRow
On Error Resume Next
'If then Find statement
If Err.Number <> 0 Then
'....
End If
x=3至lRow的
出错时继续下一步
'If then Find语句
如果错误号为0,则
'....
如果结束
我还是VBA新手,遇到了一个错误,我不知道如何修复它
我收到“运行时错误'91'对象变量或未设置块变量”
在“此处获取数据”表中,我需要将H列中的数字转移到“缺失数据”表中。此代码应该查看“缺失数据”表,并在H列中找到空白。如果确实找到空白,则会在“缺失数据”上的a列中搜索“Get Data here”以获取单元格的值。然后它从“GetData here”中获取值,并将其放入“Missing data”中。我意识到这一描述令人困惑,但如果您查看代码,注释应该会有所帮助
当我得到运行时错误时,它会突出显示S=Range(“A:A”)
如果有人能帮我,我将不胜感激
Dim x As Integer
Dim lRow As Long, S As Long
Sheets("Missing Data").Activate
'Find last row in Missing Data
lRow = Cells.Find(What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
For x = 3 To lRow
'Search for all cells without an SAP#
If Cells(x, 8) = "" Then
Sheets("Get data here").Activate
Range("A1").Activate
'Set S equal to the row where the SQP# was found
S = Range("A:A").Find(What:=Sheets("Missing Data").Cells(x, 1), _
After:=ActiveCell, _
LookAt:=xlWhole, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False).Row
'Change the value of the blank cell to the value in column H
Sheets("Missing Data").Cells(x, 8).Value = Sheets("Get data here").Cells(S, 8)
'Change the cell color to yellow if it changed
If Sheets("Missing Data").Cells(x, 8) <> "" Then
Sheets("Missing Data").Cells(x, 8).Interior.ColorIndex = 6
End If
End If
Next x
Dim x作为整数
暗淡的lRow和长的一样,S和长的一样
工作表(“缺失数据”)。激活
'查找缺失数据中的最后一行
lRow=单元格。查找(内容:=“*”_
之后:=范围(“A1”)_
看:=xlPart_
LookIn:=xl公式_
搜索顺序:=xlByRows_
搜索方向:=xlPrevious_
MatchCase:=False)。行
对于x=3至lRow
'搜索没有SAP的所有单元格#
如果单元格(x,8)=“”,则
工作表(“在此处获取数据”)。激活
范围(“A1”)。激活
'集合S等于找到SQP#的行
S=范围(“A:A”)。查找(内容:=表格(“缺失数据”)。单元格(x,1)_
之后:=ActiveCell_
看:=xlother_
LookIn:=xl公式_
搜索顺序:=xlByRows_
SearchDirection:=xlNext_
MatchCase:=False)。行
将空白单元格的值更改为H列中的值
表格(“缺少数据”)。单元格(x,8)。值=表格(“在此处获取数据”)。单元格(S,8)
'如果单元格颜色更改,请将其更改为黄色
如果表格(“缺失数据”)。单元格(x,8)”,则
表格(“缺失数据”)。单元格(x,8)。内部颜色索引=6
如果结束
如果结束
下一个x
可能找不到数据,请重试
Dim S as long
Dim R as excel.range
set R=Range("A:A").Find
if R is nothing then
'Not found, handle
else
S=R.row
end if
可能找不到数据,请重试
Dim S as long
Dim R as excel.range
set R=Range("A:A").Find
if R is nothing then
'Not found, handle
else
S=R.row
end if
将集合添加到该行的开头。在VBA中,如果要处理诸如范围对象之类的对象,则需要添加该选项<代码>设置S=Range(“A:A”)…他不是他在使用的。如果你是对的,请参见Nathan的答案。将设置添加到该行的开头。在VBA中,如果要处理诸如范围对象之类的对象,则需要添加该选项<代码>集合S=Range(“A:A”)…他没有在使用。行,你是对的,请参见Nathan回答。这会产生一个编译错误,突出显示集合R=Range(“A:A”)。Find这会产生一个编译错误,突出显示集合R=Range(“A:A”)。查找