Dynamic workbook reference based on current date

barmstr6

New Member
Joined
Jun 9, 2017
Messages
8
I want to take the current title of a workbook that has a date in the title and have it reference a previous days workbook that also has a date in it.

For example, I have a workbook titled 9/15/2023 Data Set. Within that workbook I want it to sumif a range in a workbook titled 9/14/2023 Data Set and have this continuous update as I create new daily Data Set workbooks each day so I dont have to change the reference every time a new workbook is created.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
If I understand your post, you could use a vba function in your formula to get the date value portion from the workbook name and have the function add 1 day (or is it subtract - I'm not sure which it is you need). So 09/15/2023 could become 09/16/2023 or 09/14/2023 depending whether you add or subtract.
 
Upvote 0
This function will accept the name of a workbook in the form "mm-dd-yyyy Data Set" and return the name of the workbook for the previous day.
VBA Code:
Public Function PrevDayWB(BaseWBName As String) As String

   Dim OriginalDate As Date
   
   OriginalDate = DateValue(Mid(BaseWBName, 1, 10))
   
   PrevDayWB = Format(OriginalDate - 1, "mm-dd-yyyy") & " Data Set"

End Function
 
Upvote 0
This function will accept the name of a workbook in the form "mm-dd-yyyy Data Set" and return the name of the workbook for the previous day.
VBA Code:
Public Function PrevDayWB(BaseWBName As String) As String

   Dim OriginalDate As Date
  
   OriginalDate = DateValue(Mid(BaseWBName, 1, 10))
  
   PrevDayWB = Format(OriginalDate - 1, "mm-dd-yyyy") & " Data Set"

End Function
I'm not very knowledgeable in VBA coding but where do I take this info and put it? I tried putting it into a macro to run but didn't work or maybe I messed up.
 
Upvote 0
You'll have to give me more information about your overall situation. It sounds like you just have a vague idea of what you need to do rather than an overall approach.

I want to take the current title of a workbook that has a date in the title
How do you want to take it? Where is this current title stored so that formulas or code can reference it?

and have it reference a previous days workbook that also has a date in it.
How to do you want reference the other workbook? If in a formula, what is the formula? You mentioned SUMIF but please show the actual formula.

It is possible to do this using INDIRECT without using VBA but that means the file you want to reference in the SUMIF formula must be open. If that is not useful then we'll have to use VBA. I can give you a more detailed description of what to do but the one thing that's required is where is the name of the current workbook that you're starting with.
 
Upvote 0

Forum statistics

Threads
1,215,212
Messages
6,123,651
Members
449,111
Latest member
ghennedy

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