sharky12345
Well-known Member
- Joined
- Aug 5, 2010
- Messages
- 3,380
- Office Version
-
- 2016
- Platform
-
- Windows
This may be a big ask but worth a try.....
I'd like to adapt this code to do the following if someone can help;
1) Instead of prompting for the file location, I need it to loop through all subfolders from where the active workbook sits and search for any .xls file that contains the phrase 'Log Book' in the filename - if it is found then continue the import, if not then move on to the next subfolder
2) After copying data from the source file, paste to the next empty row in column A
3) Delete the values only from the source file
4) Close the source file, saving changes
5) Surpress the message that says there is data on the clipboard
Even if someone can help with part of the list that will be progress.....
I'd like to adapt this code to do the following if someone can help;
1) Instead of prompting for the file location, I need it to loop through all subfolders from where the active workbook sits and search for any .xls file that contains the phrase 'Log Book' in the filename - if it is found then continue the import, if not then move on to the next subfolder
2) After copying data from the source file, paste to the next empty row in column A
3) Delete the values only from the source file
4) Close the source file, saving changes
5) Surpress the message that says there is data on the clipboard
Code:
Sub ImportData()
Dim Evnt As String
Dim SourceFile As Workbook
Dim filePath As String
Dim fileName As String
FileToOpen = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls")
filePath = Left$(FileToOpen, InStrRev(FileToOpen, "\"))
fileName = Mid$(FileToOpen, InStrRev(FileToOpen, "\") + 1)
'Application.ScreenUpdating = False
Application.EnableEvents = False
Set SourceFile = Workbooks.Open(fileName:=FileToOpen)
SourceFile.Sheets("Data").Activate
With SourceFile.Sheets("Data")
Range("A2:J2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
End With
ThisWorkbook.Sheets("DataImport").Range("A").PasteSpecial Paste:=xlValues
End Sub
Even if someone can help with part of the list that will be progress.....