Tengo un código vlookup que actualizará el texto "UG" en una columna de destino si el resultado coincide con la hoja de origen.
Ejemplo: El código compara "Hoja B" con "Hoja A" y si se encuentra una coincidencia en la "Hoja A", actualiza el texto "UG" en una columna en la hoja A.
Quiero hacer una pequeña modificación aquí.
En lugar de actualizar el texto "UG" en la hoja A, quiero actualizar el valor que está allí en la "Hoja B" en la columna B.
Sub UGvlookup()
Dim cl As Range, Dic As Object
Set Dic = CreateObject("Scripting.Dictionary"): Dic.Comparemode = vbTextCompare
With Sheets("Sheet A")
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("Sheet B")
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
If Dic.exists(cl.Value) Then
Sheets("Sheet A").Cells(Dic(cl.Value), 17) = "UG"
Dic.Remove (cl.Value)
End If
Next cl
End With
Respuestas
0 para la respuesta № 1tal vez estas despues de esto
Sub UGvlookup()
Dim cl As Range, Dic As Object
Set Dic = CreateObject("Scripting.Dictionary"): Dic.CompareMode = vbTextCompare
With Sheets("Sheet A")
For Each cl In .Range("B2:B" & .Cells(.Rows.count, "C").End(xlUp).Row)
Dic.Item(cl.Value) = cl.Row
Next cl
End With
With Sheets("Sheet B")
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"
Sheets("Sheet A").Cells(Dic(cl.Value), 17) = cl.Offset(, 1) "<--| write in sheet A the value of sheet B cell adjacent to the "current" one
Dic.Remove (cl.Value)
End If
Next cl
End With
End Sub