带范围的宏中的 Excel Vlookup
我正在尝试向 Excel 宏中的单元格添加 vlookup,但是我似乎无法正确获取函数的参数,也无法获取范围函数的参数
请帮助我说明如何编写代码的最后一行:
RangeStartRow = 2
RangeStartColumn = 1 + 11 + (3 * (AverageSheetIndex - RowCounter - 1))
RangeEndRow = LastCol
RangeEndColumn = 2 + 11 + (3 * (AverageSheetIndex - RowCounter - 1))
ActiveCell.Formula = WorksheetFunction.VLookup(ActiveWorkSheet.Cells(1, c), ActiveSheet.range(Cells(RangeStartRow, RangeStartColumn), Cells(RangeEndRow, RangeEndColumn)), 2, False)
我相信代码是直接的(不用介意前 4 行的值),我希望对活动单元格进行 vlookup 以在上面声明的 4 个值的范围内查找单元格(1,c)。
请让我知道如何重写代码的最后一行。
提前致谢。
I'm trying to add a vlookup to a cell in an excel macro, however I can't seem to get the arguments of the function right nor the arguments of the range function
Please help me in stating how to write last line of my code:
RangeStartRow = 2
RangeStartColumn = 1 + 11 + (3 * (AverageSheetIndex - RowCounter - 1))
RangeEndRow = LastCol
RangeEndColumn = 2 + 11 + (3 * (AverageSheetIndex - RowCounter - 1))
ActiveCell.Formula = WorksheetFunction.VLookup(ActiveWorkSheet.Cells(1, c), ActiveSheet.range(Cells(RangeStartRow, RangeStartColumn), Cells(RangeEndRow, RangeEndColumn)), 2, False)
I believe the code is straight (never mind the values of the first 4 lines), i wish to do a vlookup on the active cell to look for cell(1,c) in the range of the 4 values declared above.
Please let me know how to rewrite the last line of my code.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ActiveCell.Formula
需要一个字符串来表示您希望在单元格中使用的公式。我通常首先在工作表中手动创建公式,然后在“调试”窗口中键入(对于 C3 中的公式),
然后根据需要编辑公式并将其复制到代码中。使用 FormulaR1C1 避免检索字母:对于 ActiveCell 为 $C$4,
如果您确实想检索 MyCol 的列字母,您可以使用:
为了帮助您重新编写公式,我有时使用以下子程序,从以下位置调用调试窗口:
ActiveCell.Formula
requires a string representing the formula you want to have in the cell.I generally start by creating the formula manually in the sheet, then in the Debug window I type (for a formula in C3)
Then I edit the formula if required and I copy that in my code. Using formulaR1C1 avoid retrieving the letter: for an ActiveCell beeing $C$4,
I f you really want to retrieve the column letter of MyCol, you can use:
To help you rework your formula, I sometimes use the following sub, to be called from debug window: