How to open files from excel list using VBA and copy the latest date

jaeremata

New Member
Joined
Jan 20, 2021
Messages
24
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi, Good day. I have a concern I hope anyone can help me. I have a list of files from d2:d4 on a worksheet. I need a macro that can open one at a time copy the latest date on a specific column and sheet tab and paste it to another worksheets, then close it, then open the next, etc.
On Column D it show a link or list of file for each vendor score, I want the macro to open the file, go to sheet tab "quality" then on column J, it will look for the latest date but it on text format. Once it finds the latest date, it will copy the date and paste on another sheets name result, and then close and open the next.

1615903795543.png


I found some code, but was not able to tweak it.


VBA Code:
Sub test()
 Dim myDir As String, r As Range, fn As String, msg As String
 myDir = "c:\test\"
 For Each r In Range("c2", Range("c" & Rows.Count).End(xlUp))
 fn = Dir(myDir & r.Value)
 If fn = "" Then
 msg = msg & vbLf & r.Value
 Else
 With Workbooks.Open(myDir & fn)
 .Sheets("YourSheetName").Range("MKTG").Copy _
 ThisWorkbook.Sheets("SomeSheet").Range("SomeRange")
 .Close False
 End With
 End If
 Next
 If Len(msg) Then
 MsgBox "Not found" & msg
 End If
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,506
Messages
5,837,745
Members
430,515
Latest member
K_Lynch

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
Top