ExcelPupper
Board Regular
- Joined
- Mar 2, 2020
- Messages
- 112
- Office Version
- 2019
- Platform
- Windows
Hello. To begin with, what I need is to have to lookup the needed data from another file.
I have here the screenshot of the result of lookup and paste values when I do it manually.
Kindly check my code below for corrections. Thanks!
I have here the screenshot of the result of lookup and paste values when I do it manually.
Kindly check my code below for corrections. Thanks!
VBA Code:
Sub LookUpData()
'
'
'
' Keyboard Shortcut: Ctrl+Shift+W
'
Application.ScreenUpdating = False
Dim MyFile As String, wb As Workbook
MyFile = "C:\Users\ADMIN\Desktop\vba\SourceData.xlsm"
Set wb = Workbooks.Open(MyFile)
Workbooks("TestData").Sheets("Sheet1").Range("C2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,[SourceData.xlsm]Sheet1!C3:C5,2,FALSE)"
Range("C2").Select
Selection.Copy
Range("D2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,[SourceData.xlsm]Sheet1!C3:C5,3,FALSE)"
Range("C2:D2").Select
Selection.AutoFill Destination:=Range("C2:D4")
Range("C2:D4").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub