msquared99
Member
I have this macro that works but it asks for me to choose the file fName1 three or four times. Why?
Code:
Sub GetFile()
Dim fName1 As Variant, wbo As Workbook
Dim fName2 As Variant, wba As Workbook
Dim WBName As Worksheet
fName1 = Application.GetOpenFilename(filefilter:="Excel Files (*.XLS), *.XLS", Title:="Select the prior spreadsheet:")
If fName1 = False Then Exit Sub
Set wbo = Workbooks.Open(fName1)
wbo.Activate
fName2 = Application.GetOpenFilename(filefilter:="Excel Files (*.XLS), *.XLS", Title:="Select the current spreadsheet:")
If fName2 = False Then Exit Sub
Set wba = Workbooks.Open(fName2)
wba.Activate
Range("M2").Value = "1"
Range("M2").Select
Selection.AutoFill Destination:=Range("m2:m" & Cells(Rows.Count, "A").End(xlUp).Row)
Range("N2").FormulaR1C1 = "=RC[-13]&RC[-10]"
Range("N2").Select
Selection.AutoFill Destination:=Range("N2:N" & Cells(Rows.Count, "A").End(xlUp).Row)
Range("O2").FormulaR1C1 = "=VLOOKUP(RC[-1],' & fName1 & '!R2C14:R7C14,1,0)"
Range("O2").Select
Selection.AutoFill Destination:=Range("O2:O" & Cells(Rows.Count, "A").End(xlUp).Row)
wbo.Close savechanges:=True
wba.Close savechanges:=True
End Sub