Sub VLOOKUPs()
'Declare the variables
Dim FilterIndex As Long
Dim Title As String
Dim SourceFile As Variant
Dim n, counter, column As Integer
Dim LR As Long
' Display *.* by default
FilterIndex = 5
' Set the dialog box caption
Title = "Select a File to Import"
' Get the filename
SourceFile = Application.GetOpenFilename(, FilterIndex, Title)
' Handle return info from dialog box
If SourceFile = False Then
MsgBox "No file was selected."
Else
MsgBox "You selected " & SourceFile
End If
'VLOOKUP
Range("A9").Activate
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC2,'[(SourceFile)]Category data'!R1:R12000,R8C,FALSE)"
' Autofills the column depending on how many articles exists on the template
LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
Range("A9").AutoFill Destination:=Range("A9:A" & LR)
' Completes all the following columns
Range("A7").Select
n = Range(Selection, Selection.End(xlToRight)).Count
For counter = 7 To n
column = counter
Cells(9, column).Activate
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC2,'[(SourceFile)]Category data'!R1:R14000,R8C,FALSE)"
Next
End Sub
Bookmarks