【发布时间】:2021-05-05 20:08:59
【问题描述】:
将范围 A 中两列的值与范围 B 中的另外两列相匹配,并将范围 B 中的第三列值复制到匹配的行
我正在尝试将范围 A 中的两列值与范围 B 中的另外两列相匹配,并使用单元格链接复制第三列值,如所附屏幕截图中突出显示的单元格所示。 我能够做到这一点,但我还没有接近解决这个问题。
Sub TRIAL_Example3()
Dim k As Integer
With Worksheet("TRIAL")
Lastrow = .Range("A" & .Rows.Count).End(xlUp).Row
For k = 2 To Lastrow
If (Cells(k, 1).Value = WorksheetFunction.VLookup(Cells(k, 1).Value, Range("F2:H" & Lastrow),1, 0))
And (Cells(k, 2).Value = WorksheetFunction.VLookup(Cells(k, 1).Value, Range("F2:H" & Lastrow),1,
0)).offset(1,0) Then
Cells(k, 11).Value = WorksheetFunction.VLookup(Cells(k, 1).Value, Range("F2:H" & Lastrow), 1, 0)
Cells(k, 12).Value = WorksheetFunction.VLookup(Cells(k, 1).Value, Range("F2:H" & Lastrow), 1,
0).Offset(1, 0)
Cells(k, 13).Value = WorksheetFunction.VLookup(Cells(k, 1).Value, Range("F2:H" & Lastrow), 1,
0).Offset(2, 0)
Else:
Next k
End Sub
【问题讨论】:
-
Vlookup 不返回 Range,因此您不能将 Offset() 链接到它。
-
好的@Tim Williams 如何更改它,以便我可以使用偏移量或者有什么方法可以选择同一行中的下一列值
-
您可以使用两列
MATCH()formula 更轻松地做到这一点 - 例如 exceljet.net/formula/index-and-match-with-multiple-criteria
标签: excel vba excel-formula