2017-12-26 5 views
0

vlookupを使用し、D3と最後の行と最後の列のセルとの間のすべてのセルにsheets("formula")のセルを自動入力しようとしています。ルックアップ値はsheets("combined")にあり、ダイナミックレンジは数値または行数で表示されます。ここに私のコードは、これまでのところです:R1B1のR1C1をダイナミックレンジと組み合わせる

Sub Vlookup() 
    Dim lastcol As Integer 
    With Sheets("Formula") 
     lastcol = .Cells(1, .Columns.Count).End(xlToLeft).Column 
    End With 

    Dim lastrow As Long 
    With Sheets("Formula") 
     lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row 
    End With 

    Dim comlast As Long 
    With Sheets("Combined") 
     lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row 
    End With 

    Sheets("Formula").Range("D2").FormulaR1C1 = "=IFERROR(VLOOKUP(RC3&"" | ""&R1C,Combined!R2C3:R" & comlast & "C4, 2, FALSE),"" "")" 
    Sheets("Formula").Range("D2").AutoFill Destination:=Sheets("Formula").Range("D2:D" & lastrow), Type:=xlFillDefault 
    Sheets("Formula").Range("D2:D" & lastrow).AutoFill Destination:=Sheets("Formula").Range(Cells(2, "D"), Cells(lastrow, lastcol)), Type:=xlFillDefault 
End Sub 

私は実行時エラー「1004」取得しています:アプリケーション定義またはオブジェクト定義のエラーを。

どのような援助が

+0

'。 – GSerg

+0

ありがとうございました!それを選ぶことができませんでした。私はそれを訂正し、同じエラーがまだ出てくる – Ian

+0

これで、式を割り当てる前に、その時点で3つの値をデバッグして検査する必要があります。 – GSerg

答えて

0

をいただければ幸い私は次のように変更します

あなたがlastrow`代わりcomlast `の` assingingされている第三 `WITH`ブロックで
Dim comlast As Long 
With Sheets("Combined") 
    Comlast = .Cells(.Rows.Count, "A").End(xlUp).Row 
End With 

そして

With Sheets("Formula") 
    .Range("D2").FormulaR1C1 = "=IFERROR(VLOOKUP(RC3&"" | ""&R1C,Combined!R2C3:R" & comlast & "C4, 2, FALSE),"" "")" 
    .Range("D2").AutoFill Destination:=.Range("D2:D" & lastrow), Type:=xlFillDefault 
    .Range("D2:D" & lastrow).AutoFill Destination:=.Range(Cells(2, "D"), .Cells(lastrow, lastcol)), Type:=xlFillDefault 
End With 
+0

@Ianまだ動作しない場合は、.cells(最後の行、最後の列)の代わりに.Range(セル(最終行、最後のCol).Address)を使用する必要があります – Sercho

+0

スコットとGSerg助けてくださいが、私は将来の参照のためにアドレスを検索します – Ian

+0

@イアンの心配なし – Sercho

関連する問題