-
The whole thing!
[vba]
Option Explicit
Sub Test()
Dim LFile As String
Application.ScreenUpdating = False
Dim Pth As String
Pth = "K:\Procurement\PO DATA\"
LFile = LatestFile(Pth)
Workbooks.Open Pth & LFile
Windows("Shipping Method Macro.xls").Activate
With Range("F7")
.FormulaR1C1 = "=VLOOKUP(RC[-1],'[" & LFile & "]MASTER'!C1:C20,20,0)"
.AutoFill Destination:=Range("F7:F50"), Type:=xlFillDefault
End With
Range("F7:F50").Select
End Sub
Function LatestFile(Pth As String)
Dim fdate, tmp, fname As String, LastFile As String
tmp = 0
fname = Dir(Pth & "*.xls")
Do
On Error Resume Next
fdate = Split(fname, "of ")(1)
fdate = CDate(Split(fdate, ".")(0))
If fdate > tmp Then
tmp = fdate
LastFile = fname
End If
fname = Dir
Loop Until fname = ""
LatestFile = LastFile
End Function
[/vba]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules