Hi all - I recorded a macro to open a file and find the latest file. I want to know since the date here changes daily, how do I call it from my vlookup?
Sub Open_Argus()
'
' Open Latest Argus File
'---Opens a sheet based on date, searches backward from today til it finds a matching date
Dim dtTestDate As Date
Dim sStartWB As String
Const sPath As String = "V:\Security\ARGUS\Argus Users Lists\2018"
dtEarliest = Date - 5
'--to stop loop if file not found by earliest valid date.
dtTestDate = Date
sStartWB = ActiveWorkbook.Name
While ActiveWorkbook.Name = sStartWB And dtTestDate >= dtEarliest
On Error Resume Next
Workbooks.Open sPath & "IPNS Security " & Format(dtTestDate, "MMDDYYYY") & ".xlsx"
dtTestDate = dtTestDate - 1
On Error GoTo 0
Wend
If ActiveWorkbook.Name = sStartWB Then MsgBox "Earlier file not found."
end sub
heres my formula for vlookup, the date here should be based from the result above.
Dim LR As Long
LR = Range("E" & Rows.Count).End(xlUp).Row
Range("Q2").Select
Range("Q2:Q" & LR).FormulaR1C1 = _
"=IF(VLOOKUP(RC[-8],'[IPNS Security 07232018.xlsx]Sheet1'!C8,1,FALSE),""ARGUS"")"
Sub Open_Argus()
'
' Open Latest Argus File
'---Opens a sheet based on date, searches backward from today til it finds a matching date
Dim dtTestDate As Date
Dim sStartWB As String
Const sPath As String = "V:\Security\ARGUS\Argus Users Lists\2018"
dtEarliest = Date - 5
'--to stop loop if file not found by earliest valid date.
dtTestDate = Date
sStartWB = ActiveWorkbook.Name
While ActiveWorkbook.Name = sStartWB And dtTestDate >= dtEarliest
On Error Resume Next
Workbooks.Open sPath & "IPNS Security " & Format(dtTestDate, "MMDDYYYY") & ".xlsx"
dtTestDate = dtTestDate - 1
On Error GoTo 0
Wend
If ActiveWorkbook.Name = sStartWB Then MsgBox "Earlier file not found."
end sub
heres my formula for vlookup, the date here should be based from the result above.
Dim LR As Long
LR = Range("E" & Rows.Count).End(xlUp).Row
Range("Q2").Select
Range("Q2:Q" & LR).FormulaR1C1 = _
"=IF(VLOOKUP(RC[-8],'[IPNS Security 07232018.xlsx]Sheet1'!C8,1,FALSE),""ARGUS"")"