Vickytayade18
New Member
Hi all, I am starting my VBA journey and i have requirement of V LOOKUP between 2 files.
I have prepared a code to paste a value from "source file" into Output file, but i am not able to solve the error, which is why i need your help. Please help me to get a solution for it.
my requirement is as " When i paste part no's in "B4"onward in macro and run it, it should go to "Source file" and fetch the 4 values and gives output.
I have prepared a code to paste a value from "source file" into Output file, but i am not able to solve the error, which is why i need your help. Please help me to get a solution for it.
my requirement is as " When i paste part no's in "B4"onward in macro and run it, it should go to "Source file" and fetch the 4 values and gives output.
Code:
Sub HTS_TEMPLATE()
Dim PartsWS As Worksheet, dataWS As Worksheet
Dim PartsLastRow As Long, DatalastRow As Long, X As Long
Dim DataRng As Range
Set PartsWS = ThisWorkbook.Worksheets("Item number")
Set dataWS = ThisWorkbook.Worksheets("Data")
PartsLastRow = PartsWS.Range("A" & Rows.Count).End(xlUp).Row
DatalastRow = dataWS.Range("A" & Rows.Count).End(xlUp).Row
Set DataRng = dataWS.Range("A2:l" & DatalastRow)
'For X = 2 To PartsLastRow
'On Error Resume Next
dataWS.Range("B" & X).Value = Application.WorksheetFunction.vlookup( _
dataWS.Range("A" & X).Value, DataRng, 2, False)
'Next X
PartsWS.Select
Range("G4").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-5],[SOURCE.xlsx]Sheet1!R1C1:R10C4,2,0)"
Range("G4").Select
Selection.AutoFill Destination:=Range("G4:G12")
Range("G4:G12").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub