I hope I can explain this correctly. I have a process that of moving data from a group of five files to five corresponding files in another directory. It works well but it is not very efficient.
I use a sub to call each one by one. It works but it just doesn't seem to be very efficient. Then I wondered "what if I had a lot of these files"? That would be a lot of code and the file could become huge. So then I though "What if I had the names of the file listed in column A and their corresponding file where the data needs to be moved to in column B? Below is the code I have used to move the data. I also included the range to help explain. I'm using 365.
Sub POST_ALL()
POST_FILE_1
POST_FILE_2
POST_FILE_3
POST_FILE_4
POST_FILE_5
End Sub
Private Sub POST_FILE_1()
'
' POST_FILE_1 Macro
' COPY DATA FROM TEST FILE 1 TO RECIVE FILE 1 SAVE AND CLOSE FILE
'
Application.ScreenUpdating = False
'
ChDir "H:\Personal\STOP LOSS\UMR Files\Original Report Data"
Workbooks.Open Filename:= _
"H:\Personal\STOP LOSS\UMR Files\Original Report Data\Sending Test File 1.xlsx"
Range("A2:M4").Select
Selection.Copy
ActiveWindow.Close
ChDir "H:\Personal\STOP LOSS\UMR Files\Reports To Be Sent"
Workbooks.Open Filename:= _
"H:\Personal\STOP LOSS\UMR Files\Reports To Be Sent\Receiving Test File 1.xlsx"
Sheets("Detail").Select
Range("A5").Select
ActiveSheet.PasteSpecial Format:="Unicode Text", Link:=False, _
DisplayAsIcon:=False, NoHTMLFormatting:=True
Columns("B:B").EntireColumn.AutoFit
Sheets("Summary").Select
ActiveWorkbook.Save
ActiveWindow.Close
End Sub
Private Sub POST_FILE_2()
'
' POST_FILE_1 Macro
' COPY DATA FROM TEST FILE 2 TO RECIVE FILE 2 SAVE AND CLOSE FILE
'
Application.ScreenUpdating = False
'
ChDir "H:\Personal\STOP LOSS\UMR Files\Original Report Data"
Workbooks.Open Filename:= _
"H:\Personal\STOP LOSS\UMR Files\Original Report Data\Sending Test File 2.xlsx"
Range("A2:M4").Select
Selection.Copy
ActiveWindow.Close
(etc. etc. and so on )
in Sheet1
I use a sub to call each one by one. It works but it just doesn't seem to be very efficient. Then I wondered "what if I had a lot of these files"? That would be a lot of code and the file could become huge. So then I though "What if I had the names of the file listed in column A and their corresponding file where the data needs to be moved to in column B? Below is the code I have used to move the data. I also included the range to help explain. I'm using 365.
Sub POST_ALL()
POST_FILE_1
POST_FILE_2
POST_FILE_3
POST_FILE_4
POST_FILE_5
End Sub
Private Sub POST_FILE_1()
'
' POST_FILE_1 Macro
' COPY DATA FROM TEST FILE 1 TO RECIVE FILE 1 SAVE AND CLOSE FILE
'
Application.ScreenUpdating = False
'
ChDir "H:\Personal\STOP LOSS\UMR Files\Original Report Data"
Workbooks.Open Filename:= _
"H:\Personal\STOP LOSS\UMR Files\Original Report Data\Sending Test File 1.xlsx"
Range("A2:M4").Select
Selection.Copy
ActiveWindow.Close
ChDir "H:\Personal\STOP LOSS\UMR Files\Reports To Be Sent"
Workbooks.Open Filename:= _
"H:\Personal\STOP LOSS\UMR Files\Reports To Be Sent\Receiving Test File 1.xlsx"
Sheets("Detail").Select
Range("A5").Select
ActiveSheet.PasteSpecial Format:="Unicode Text", Link:=False, _
DisplayAsIcon:=False, NoHTMLFormatting:=True
Columns("B:B").EntireColumn.AutoFit
Sheets("Summary").Select
ActiveWorkbook.Save
ActiveWindow.Close
End Sub
Private Sub POST_FILE_2()
'
' POST_FILE_1 Macro
' COPY DATA FROM TEST FILE 2 TO RECIVE FILE 2 SAVE AND CLOSE FILE
'
Application.ScreenUpdating = False
'
ChDir "H:\Personal\STOP LOSS\UMR Files\Original Report Data"
Workbooks.Open Filename:= _
"H:\Personal\STOP LOSS\UMR Files\Original Report Data\Sending Test File 2.xlsx"
Range("A2:M4").Select
Selection.Copy
ActiveWindow.Close
(etc. etc. and so on )
in Sheet1
DATA TEST RECEIVING FILES | DATA TEST SENDING FILES |
SENDING TEST FIEL 1 | RECEIVING TEST FILE 1 |
SENDING TEST FIEL 2 | RECEIVING TEST FILE 2 |
SENDING TEST FIEL 3 | RECEIVING TEST FILE 3 |
SENDING TEST FIEL 4 | RECEIVING TEST FILE 4 |
SENDING TEST FIEL 5 | RECEIVING TEST FILE 5 |
SENDING TEST FIEL 6 | RECEIVING TEST FILE 6 |
SENDING TEST FIEL 7 | RECEIVING TEST FILE 7 |
SENDING TEST FIEL 8 | RECEIVING TEST FILE 8 |
SENDING TEST FIEL 9 | RECEIVING TEST FILE 9 |
SENDING TEST FIEL 10 | RECEIVING TEST FILE 10 |
SENDING TEST FIEL 11 | RECEIVING TEST FILE 11 |
SENDING TEST FIEL 12 | RECEIVING TEST FILE 12 |
SENDING TEST FIEL 13 | RECEIVING TEST FILE 13 |
SENDING TEST FIEL 14 | RECEIVING TEST FILE 14 |
SENDING TEST FIEL 15 | RECEIVING TEST FILE 15 |