2016-08-18 139 views
0

编写宏以运行跨列中每个单元格运行VLOOKUP的循环。我收到“运行时错误”424'Object required'错误,但无法确定主要问题。任何见解或帮助表示赞赏。运行时错误'424'所需的对象

两个问题: *运行时错误'424'所需对象 *循环继续通过数据的最后一个单元格,直到在停止之前打包或Excel限制为止。使用.ActiveCell和.Value的点运算符不起作用。 enter image description here

Sub New_contact_info() 

serverName = Cells.Range("AS:AS") 
contactInfo = Application.WorksheetFunction.VLookup(serverName, Worksheets("All Active Assets").Range("A:C"), 3, False) 

Cells.Range("AM:AM") = contactInfo 

For Each cell In serverName 
If serverName <> "" Then 
serverName.ValueOffset(0, -5) = contactInfo 
End If 

Next cell 

End Sub 
+1

你确定它没有前人的精力是这样的:“如果细胞<>‘’那 – Vityata

+0

这条线现在已经很清楚,下一行抛出了同样的错误,我已经现在尝试“cell.Offset(0,5)= contactInfo”无效 – 1up

+1

只是一个建议 - 在代码的顶部写上“Option Explicit”,然后从顶部菜单执行“Debug”>“Compile”。显示所有编译错误。请参阅此处“Option Explicit” - > http://www.excel-easy.com/vba/examples/option-explicit.html – Vityata

回答

0

你必须设置使用 “设置” 关键字的范围SERVERNAME。 这给一试:

Sub New_contact_info() 
    dim serverName as Range 

    set serverName = Cells.Range("AS:AS") 
    contactInfo = Application.WorksheetFunction.VLookup(serverName, Worksheets("All Active Assets").Range("A:C"), 3, False) 

    Cells.Range("AM:AM").value = contactInfo 

    For Each cell In serverName 
    If serverName.value <> "" Then 
     serverName.Value.Offset(0, -5) = contactInfo 
    End If 

    Next cell 

End Sub 
相关问题