2017-07-05 2 views
1

vlookupで列インデックスno dを呼び出す方法"=vlookup(RC[-15],"& Rg.Address(True, True, xlR1C1, xlExternal) & ",d,False)"は正しいですか? (別のワークブックに1つのワークブックを使用してVLOOKUPに注意してください)Vlookupで列インデックス番号を呼び出す方法:VBA

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 

答えて

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)" 

daVariantのように定義されている間Dim d, a, Lastrow As Longの定義を、唯一Lastrow As Longを意味します。

この行をDim d As Long, a As Long, Lastrow As Long

に変更してください
関連する問題