Hi everyone,
We can shorten Dave's code slightly again (I think!?) to read as below, with the aim being to minimise the repeated actions within the loop (ie activating the "master" workbook each time).
Sub ChangeDateValues()
Dim myDir As String, fn As String
myDir = "Z:\My Documents\Analyst Recommendations\Top Analysts\Analysts Results\JP Morgan\Test\"
fn = Dir(myDir & "*.xlsm")
Do While fn <> ""
If fn <> ThisWorkbook.Name Then
Workbooks.Open (myDir & fn)
ThisWorkbook.Worksheets("Sheet1").Range("A6:A7").Copy Destination:=Workbooks(fn).Sheets(20).Cells(5, 2)
Workbooks(fn).Close True 'If you want to save the paste, this must be true
End If
fn = Dir
Loop
End Sub
If you only want the values to be transferred & you aren't concerned about formatting etc, you can probably (untested!) use...
Sub ChangeDateValues()
Dim myDir As String, fn As String
myDir = "Z:\My Documents\Analyst Recommendations\Top Analysts\Analysts Results\JP Morgan\Test\"
fn = Dir(myDir & "*.xlsm")
Do While fn <> ""
If fn <> ThisWorkbook.Name Then
Workbooks.Open (myDir & fn)
'is my range conversion right?
Workbooks(fn).Sheets(20).range("B5:B6").value = ThisWorkbook.Worksheets("Sheet1").Range("A6:A7").value
'or the value2 property
Workbooks(fn).Sheets(20).range("B5:B6").value2 = ThisWorkbook.Worksheets("Sheet1").Range("A6:A7").value2
Workbooks(fn).Close True 'If you want to save the paste, this must be true
End If
fn = Dir
Loop
End Sub
Rob
Bookmarks