我想做一個查找循環來搜索列表中的值,並在4個細節中返回它們,但我的公式不工作,它只是返回我的變量名稱細胞。Vlookup在循環中複製信息
Private Sub copydata() 'copy fornecedor data if match
Dim rng As Range
Dim rang As Integer
Dim rang2 As Integer
Dim cell As Variant
Dim rang3 As Range
rang = Worksheets("Plan1").Range("A2").End(xlDown).Row
Set rng = ActiveSheet.Range("A2:A" & rang)
Set rang3 = Range("Plan1!$G1:$K1000")
rang2 = 1
For Each cell In rng
rang2 = rang2 + 1
If cell.Interior.Color = 65535 Then
cell.Offset(0, 1).Formula = "=vlookup(cell,rang3,2,0)"
cell.Offset(0, 2).Formula = "=vlookup(cell,rang3,2,0)"
cell.Offset(0, 3).Formula = "=vlookup(cell,rang3,2,0)"
cell.Offset(0, 4).Formula = "=vlookup(cell,rang3,2,0)"
End If
Next cell
End Sub
在一個側面說明中,我會找到第一行使用單元格匹配的實例,然後使用索引或偏移量來獲得其餘的值,沒有一點查找值4次。 –