使用excel中的新描述更新部件列表

时间:2015-09-02 21:06:38

标签: excel vba excel-vba formula

我有两张床单。每个都有大约20k的零件号,我需要从Sheet 1 col中获取零件号。 B,检查它是否存在于Sheet 2 col.A中的任何位置,如果确实存在,则获取Sheet 2 col的内容。该行的B,并将其粘贴到具有公式的单元格中。

表示我只能排序和复制/粘贴部件号列表不匹配100%

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

考虑以下示例:

Sub PopulateDescriptions()
    Dim objList As Object
    Dim objSrc As Range
    Dim objDst As Range
    Dim arrList() As Variant
    Dim arrDesc() As Variant
    Dim i As Long

    Set objList = CreateObject("Scripting.Dictionary")
    With Sheets("Sheet 2")
        arrList = Intersect(.UsedRange, .Range("A:B")).Value
    End With
    For i = 1 To UBound(arrList, 1)
        objList(arrList(i, 1)) = arrList(i, 2)
    Next

    With Sheets("Sheet 1")
        Set objSrc = Intersect(.UsedRange.Rows, .Range("A:A"))
    End With
    Set objDst = objSrc.Offset(0, 2) ' column C
    arrList = objSrc.Value
    arrDesc = objDst.Value
    For i = 1 To UBound(arrList, 1)
        If objList.Exists(arrList(i, 1)) Then
            arrDesc(i, 1) = objList(arrList(i, 1))
        End If
    Next
    objDst.Value = arrDesc
End Sub