如何在vlookup中调用列索引no d
。 "=vlookup(RC[-15],"& Rg.Address(True, True, xlR1C1, xlExternal) & ",d,False)"
这是正确的吗?请参阅下面的代码(注意Vlookup使用一个工作簿到另一个工作簿)
Sub Vlkuprangcall()
Dim strColumn As String
Dim Rg As Range
Dim wb2 As Workbook
Dim d, a, Lastrow As Long
Set wb2 = Workbooks.Open("C:\Users\ashokkumar.d\Desktop\Test\IC Raphael\Janalakshmi\MIS\MIS.xlsx")
Set Rg = wb2.Sheets(3).Range("A3:Z10000")
d = 6
Application.Workbooks(2).Activate
With ActiveSheet
a = ActiveCell.Column
Lastrow = 100
strColumn = Split(ActiveCell.Address, "$")(1)
ActiveCell.FormulaR1C1 = "=vlookup(RC[-15],"& Rg.Address(True, True, xlR1C1, xlExternal) & ",d,False)"
ActiveCell.AutoFill Destination:=Range(ActiveCell, Range(strColumn & Lastrow))
End With
End Sub
答案 0 :(得分:1)
您需要取出d
之外的"
变量。
替换FormulaR1C1
行:
ActiveCell.FormulaR1C1 = "=vlookup(RC[-15],"& Rg.Address(True, True, xlR1C1, xlExternal) & ",d,False)"
使用:
ActiveCell.FormulaR1C1 = "=vlookup(RC[-15]," & Rg.Address(True, True, xlR1C1, xlExternal) & "," & d & ",False)"
注意:定义Dim d, a, Lastrow As Long
,仅表示Lastrow As Long
,而d
和a
将定义为Variant
。< / p>
将此行更改为Dim d As Long, a As Long, Lastrow As Long