我正在尝试设置 VB,以便可以对动态范围的值进行 VLOOKUP。它总是从同一个地方开始,但它可能会根据 H4 中的任何值进一步向下结束。
编辑:这是代码,它可以工作。
谢谢亚历克斯!
Public Sub State()
Dim refRng As Range, ref As Range, dataRng As Range
Dim i As Variant
Dim count As Integer
i = Sheet2.Range("H1").Value
i = i + 3 'offset of when to start
Set refRng = Sheet2.Range("D8:" & Cells(8, i).Address) '//horizontal range of look up values
Set dataRng = Sheet13.Range("A:C") '//data block you want to look up value in
For Each ref In refRng
ref.Offset(1, 0) = Application.WorksheetFunction.VLookup(refRng, dataRng, 2, True)
Next ref
End Sub