how to do vlookup in macros of two different excel books

0

Hello, good morning, my colleagues, I have a question that I have not yet been able to solve, it turns out that I have two excel books A and B, in one of them one record as a database and in the other a list of product codes and what I want is to look for the data in book B according to the code of the book A with macros Vlookup some help will be very grateful thank you !. Here I leave a few lines of code. Application.CutCopyMode = False

conteo As Long
Dim Marca As Variant
Dim Rango As Variant
Dim Archivo As String
Dim bCarpeta As String
Dim codigoBuscado As String
Dim Final As Long

    bCarpeta = ActiveWorkbook.Path & "\"
    Archivo = Dir(bCarpeta & "Maestro Dinet" & "*.xl*")
    Workbooks.OpenText Filename:=Archivo
    Application.ScreenUpdating = False
    Archivo = ActiveWorkbook.Name
    Windows(Archivo).Activate

    ActiveCell.FormulaR1C1 = _
    "=VLOOKUP(RC[-5],'[Maestro Dinet.xlsb]01'!C1:C38,31,0)"
    Range("G5").Select
    Selection.AutoFill Destination:=Range("G5:G86") ', Type:=xlFillDefault

MsgBox "Proceso terminado", vbInformation, "Resultado"
    
asked by Federico Meza 25.05.2018 в 11:16
source

1 answer

0

The problem is that the code created by the macro recorder does not work well.

Try something like this:

With Sheets("Hoja_donde_aplicas_buscarv").Range("G5:G86")
    .Formula = "=VLOOKUP(RC[-5],'" & Archivo & "01'!C1:C38,31,0)"
    .Formula = .Value
End With
    
answered by 28.05.2018 в 09:15