excelhelp9876

New Member
Joined
Aug 31, 2022
Messages
1
Office Version
  1. 2010
Platform
  1. MacOS
Hi, this is the vlookup I currently have (that works)

VLOOKUP(F2,'\\documents\August\[File Name 30.08.22.xlsm]Sheet 1'!$F:$Z,21,0)

The issue is that everyday I have to reset the formula with the prior working day so that it's pulling through the latest comments. I'm trying to create a static formula that will automatically lookup to the prior days sheet.

How do I get the File name to be yesterday's date. I've got - =WORKDAY(TODAY(),-1) but I can't get this into the vlookup without it erroring.

Any help is really appreciated!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
welcome to forum, try this:
VBA Code:
Sub test3()
Dim dd As String
Dim mm As String
Dim yy As String

'VLOOKUP(F2,'\\documents\August\[File Name 30.08.22.xlsm]Sheet 1'!$F:$Z,21,0)
firstbit = "VLOOKUP(F2,'\\documents\August\[File Name "
secondbit = ".xlsm]Sheet 1'!$F:$Z,21,0)"
tt = (Now() - 1)
dd = Day(tt)
If Len(dd) < 2 Then dd = "0" & dd
mm = Month(tt)
If Len(mm) < 2 Then mm = "0" & mm
yy = Year(tt) - 2000
dt = dd & "." & mm & "." & yy

formul = firstbit & dt & secondbit
MsgBox formul

End Sub
 
Upvote 0
Offthelip's code would already solve the question, nevertheless let me suggest this variant:
VBA Code:
Dim FirstBit As String, fBit2 As String, SecondBit As String, MidBit As String
Dim preDate As Date, nForm As String
'
FirstBit = "=VLOOKUP(F2,'\\documents\"
fBit2 = "\[File Name "
SecondBit = ".xlsm]Sheet 1'!$F:$Z,21,0)"
preDate = Application.WorksheetFunction.WorkDay(Date, -1)
MidBit = Format(preDate, "mmmm") & fBit2 & Format(preDate, "dd.mm.yy")
nForm = FirstBit & MidBit & SecondBit

'MsgBox nForm
Range("XY").Formula = nForm        'Your Range
This uses WORKDAY to determine the previous date and use Format to create the strings that fit in the new formula
Also, I assume that "August" in the formula will soon become "September", then I modified also that portion of the path

Try...
 
Upvote 0
Solution

Forum statistics

Threads
1,224,815
Messages
6,181,135
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top