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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,223,767
Messages
6,174,390
Members
452,561
Latest member
amir5104

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