解决了Nathan_SAV有正确的想法。对于任何看过这个以供参考的人,我将代码更改为
For x = 3 To lRow
On Error Resume Next
'If then Find statement
If Err.Number <> 0 Then
'....
End If
我还是VBA的新手,我遇到了错误,我无法弄清楚如何修复它。
我收到了&#34;运行时错误&#39; 91&#39;对象变量或未设置块变量&#34;
在&#34;获取数据&#34;表格我在H栏中有数字我需要转移到&#34;缺少数据&#34;片。该代码应该查看&#34;缺失数据&#34;在表H中找到并找到空白。如果找到空白则搜索&#34;在此处获取数据&#34;对于A列中单元格的值&#34;缺少数据&#34;。然后它取值来自&#34;在这里获取数据&#34;并将其置于&#34;缺少数据&#34;。我意识到这种描述令人困惑,但如果你看一下代码,评论应该有所帮助。
当我得到运行时错误时,突出显示S =范围(&#34; A:A&#34;)....
如果有人能帮助我,我会很感激。
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
答案 0 :(得分:1)
可能找不到数据,请尝试
message.setRecipients(Message.RecipientType.TO, toAddrs);