我正在尝试在vlookup
中使用sheets("formula").range("D3")
并将其自动填充到D3和sheets("formula")
中最后一行和最后一列中的单元格之间的所有单元格。查找值在sheets("combined")
中,其具有数量或行的动态范围。到目前为止,这是我的代码:
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':应用程序定义或对象定义的错误。
任何援助将不胜感激
我会改变以下内容:
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