VBA to Pull Data from Closed Workbook Based on Date

Just Mike

New Member
Joined
Jul 19, 2019
Messages
2
Hi Everyone

Hoping I can get some help on a Macro I am trying to create.

I have my from path and in the from path I have hundreds of files each with a difference date.

I would like to only copy data from the closed workbook that ends in COLLAT_COB_MMMMYYDD and where MMMMYYDD is equal to yesterdays business date.

So today is 1/22/2021 but the file would show COLLAT_COB 20210121

I have found macros that can copy over all the files but I am just looking to copy of the specific file based on the above criteria.

Thank you for your time
 

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".
Hi,

Compare your filename before doing any operation as below:

The dates in file name is in format YYYYMMDD while In the query you mentioned MMMMYYDD

VBA Code:
Dim fileName As String
fileName = Mid(ThisWorkbook.Name, 12, 8)
if Left(fileName, 8) = CStr(Format(Now() - 1, "YYYYMMDD")) then
   'type your code
end if
 
Upvote 0

Forum statistics

Threads
1,214,581
Messages
6,120,372
Members
448,957
Latest member
BatCoder

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