简体   繁体   English

Excel VBA中vlookup的动态范围

[英]Dynamic range for vlookup in Excel VBA

I am looking for a possibility to set a dynamic range. 我正在寻找设置动态范围的可能性。 The problem is that Excel does not accept the typing. 问题在于Excel不接受键入。 Five rows of a matrix should be looked through for each a. 对于每个a,应查看矩阵的五行。 The vlookup is working with a fixed range such as "E43:AT47" but not for a combined one. vlookup在固定范围内工作,例如“ E43:AT47”,但不适用于组合范围。

        Range_Zeile_Start = 5 * a - 12
        Range_Zeile_End = 5 * a - 8
        Range_Count = "R" & Range_Zeile_Start & "C5:R" & Range_Zeile_End & "C46"

        Fahrzeit_kk = Application.WorksheetFunction.VLookup(Cells(1, b).Value, Range_Count, 42, False)

You need to set-up your Range correct. 您需要正确设置范围。

See code below: 参见下面的代码:

Dim VlookRng As Range

Range_Zeile_Start = 5 * a - 12
Range_Zeile_End = 5 * a - 8

' set up the Range for the Vlookup
Set VlookRng = Range(Cells(Range_Zeile_Start, 5), Cells(Range_Zeile_End, 46))
Fahrzeit_kk = Application.WorksheetFunction.VLookup(Cells(1, b).value, VlookRng, 42, False)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM