基于vlookup更新列

时间:2017-01-15 04:11:06

标签: excel vba vlookup

我有以下代码执行vlookup。检查表格" UG列表中的值是否为" col A,存在于表格" Latency" B col。

目前,我获得了在工作表" UG列表"中粘贴的值。本身如果有匹配。但相反,我需要文字" UG"要在Q中更新"延迟"如果匹配,请填写表格。

有任何建议可以实现吗?

Sub vlookup()
Dim cl As Range, Dic As Object
Set Dic = CreateObject("Scripting.Dictionary"): Dic.Comparemode =    vbTextCompare
With Sheets("Latency")
For Each cl In .Range("B2:B" & .Cells(Rows.count, "C").End(xlUp).Row)
    If Not Dic.exists(cl.Value) Then Dic.Add cl.Value, cl.Row
Next cl
End With
With Sheets("UG list")
For Each cl In .Range("A2:A" & .Cells(Rows.count, "A").End(xlUp).Row)
    If Dic.exists(cl.Value) Then cl.Offset(, 1).Value = cl.Value
Next cl
End With
Set Dic = Nothing
End Sub

1 个答案:

答案 0 :(得分:0)

With Sheets("UG list")
    For Each cl In .Range("A2:A" & .Cells(Rows.Count, "A").End(xlUp).Row)
        If Dic.exists(cl.Value) Then
            Sheets("Latency").Cells(Dic(cl.Value), 17) = "UG"
        End If
    Next cl
End With

17是Q的列#。您已经将行号存储在字典中,所以只需使用它。