Home » excel » excel – Vlookup formula displaying 1004 error. Work around is also failing

excel – Vlookup formula displaying 1004 error. Work around is also failing

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’m trying to insert a Vlookup formula on some filtered data but I’ve run into a few errors. Below is the code I’m using. (Not all of it, just the section with the issue)

'Sells
Dim SellData As Worksheet
Set SellData = Transactions.Sheets("SellData")
Dim lrSell As Long
lrSell = SellData.Cells(Rows.Count, "H").End(xlUp).Row
Dim SellDataRange As Range
Set SellDataRange = SellData.Range("A1:CW" & lrSell)

PrVFormat = Format$(Transactions.Sheets("others").Range("B2").Value, "dd-mmm-yy")
SellDataRange.AutoFilter Field:=8, Criteria1:=PrVFormat
lrSellFilter = SellData.Cells(Rows.Count, "H").End(xlUp).Row

With SellData.Range("CW2:CW" & lrSellFilter).SpecialCells(xlCellTypeVisible)
  .Cells.FormulaR1C1 = "=VLOOKUP(RC[-12],'[OtherWorkbook.xlsx]new'!$A:$K,11,FALSE)"   '1004 error
  SellData.Calculate
SellDataRange.AutoFilter Field:=8
SellData.Range("CW1:CW" & lrSell).Copy
SellData.Range("CW1").PasteSpecial xlPasteValues
End With

The line I’m having an issue with is

.Cells.FormulaR1C1 = "=VLOOKUP(RC[-12],'[OtherWorkbook.xlsx]new'!$A:$K,11,FALSE)"  

If I leave the $, I receive a 1004 error. If I remove the $, the formula end up like this

=VLOOKUP(CK1578,'[OtherWorkbook.xlsx]new’!A:(K),11,FALSE)

‘Notice the parenthesis around the K. That shouldn’t be there.

Thank you in advance for your assistance

How to&Answers:

You cannot mix R1C1 and A1 nomenclature.

.Cells.FormulaR1C1 = "=VLOOKUP(RC[-12],'[OtherWorkbook.xlsx]new'!C1:C11,11,FALSE)"