Hello I'm looking to get some help with the code I have. I have the below code that opens multiples files from list, selects 2 tabs and copies values into 2 tabs into another workbook.
For reference and clarity:
FP Plan Data & OT Plan Data are worksheets to copy from
FP Plan Export & OT Plan Export are worksheets of another workbook to copy into
Sheet1 contains the list of filepaths to open
Everyone in this community has been extremely helpful and insightful so any tips or pointers would be greatly appreciated!
For reference and clarity:
FP Plan Data & OT Plan Data are worksheets to copy from
FP Plan Export & OT Plan Export are worksheets of another workbook to copy into
Sheet1 contains the list of filepaths to open
Everyone in this community has been extremely helpful and insightful so any tips or pointers would be greatly appreciated!
VBA Code:
Public Sub Copy_values()
'declare varibales
Dim fileCells As Range, fileCell As Range
Dim destCells As Range, r As Long
Dim fromWorkbook As Workbook
With ThisWorkbook
'location of filenames to open
With .Worksheets("Sheet1")
'sets the number of times/files to do the prodecure based on the last low of data
Set fileCells = .Range(.Range("A1"), .Cells(.Rows.Count, "A").End(xlUp))
End With
'paste values from files into worksheet
Set destCells = .Worksheets(Array("FP Plan Extract", "OT Plan Extract")).Range("B8:EZ20")
End With
'disable screen updating
Application.ScreenUpdating = False
r = 0
'for each file that is listed do the procedure
For Each fileCell In fileCells
'open workbooks as read only, don't update links
Set fromWorkbook = Workbooks.Open(fileCell.Value, ReadOnly:=True, UpdateLinks:=0)
'copy values from open file
destCells.Offset(r).Value = fromWorkbook.Worksheets(Array("FP Plan Data", "OT Plan Data")).Range("A7:EY19").Value
'close open file without saving
fromWorkbook.Close SaveChanges:=False
'next file's 13 row of data
r = r + 13
DoEvents
Next
'enable screen updating
Application.ScreenUpdating = True
'prompt when finished
MsgBox "Finished"