试试这个
Sub Demo()
Dim srcSht As Worksheet, destSht As Worksheet
Dim srcLR As Long, destLR As Long
Dim cel As Range, srcRng As Range
Set srcSht = ThisWorkbook.Sheets("Results for init")
Set destSht = ThisWorkbook.Sheets("Result Tab")
With srcSht
srcLR = .Cells(.Rows.Count, "C").End(xlUp).Row 'get last row with data in srcSht using Column C
Set srcRng = .Range("C2:E" & srcLR) 'set range for look up
End With
With destSht
destLR = .Cells(.Rows.Count, "A").End(xlUp).Row 'get last row with data in destSht using Column A
For Each cel In .Range("A2:A" & destLR) 'loop through each cell in Column a of destSht
cel.Offset(0, 1).Value = WorksheetFunction.VLookup(cel, srcRng, 3, False) 'get vlookup result
Next cel
End With
End Sub
使用公式的解决方案:
假设您的数据在工作表Results for init 中,然后在工作表Result tab 的Cell B2 中输入以下公式
=VLOOKUP(A2,'Results for init'!$C$2:$E$10,3,FALSE)
或
=INDEX('Results for init'!$E$2:$E$10,MATCH(Sheet3!A2,'Results for init'!$C$2:$C$10,0))
根据需要拖动/复制公式。根据您的数据更改范围2:10。参考图片。
结果标签工作表