Hey everyone! I was doing some googling for help with some data extraction and found a code that was actually provided on this forum some years ago and I tweaked it to fit my exact situation.
So the code below takes a column (and some other stuff) from multiple workbooks in the same folder and pastes it onto a master workbook. It's something like 1000 workbooks I'm dealing with. The code runs completely fine, except when I run it, every time it goes through a workbook, I get a pop-up asking if I want to save the changes made to the workbook (I then have to press Save/Don't Save/Cancel for the code to continue running). Seeing that I have 1000 workbooks, clicking 1000 times doesn't seem ideal.
Anyone have an idea how to rectify it? I feel like there's a simple solution, but I'm not too sure.
Thanks, all!
So the code below takes a column (and some other stuff) from multiple workbooks in the same folder and pastes it onto a master workbook. It's something like 1000 workbooks I'm dealing with. The code runs completely fine, except when I run it, every time it goes through a workbook, I get a pop-up asking if I want to save the changes made to the workbook (I then have to press Save/Don't Save/Cancel for the code to continue running). Seeing that I have 1000 workbooks, clicking 1000 times doesn't seem ideal.
Anyone have an idea how to rectify it? I feel like there's a simple solution, but I'm not too sure.
Code:
Sub runMerge()Dim fs As FileSystemObject
Dim targetPath As String
Dim haveTarget As Boolean
Dim thefile As File
Dim currRow As Long
Dim sourceFile As String
Dim a1 As String
Dim currCol As Long
Dim i As Integer
Dim starttime As Date
Dim endtime As Date
starttime = Now
haveTarget = False
Set fs = CreateObject("Scripting.FileSystemObject")
While Not haveTarget
targetPath = InputBox("Result Folder", "Target Folder", "C:\Users\XianFang\Desktop\Rainwater Project\Test")
haveTarget = fs.FolderExists(targetPath)
Wend
Set theFolder = fs.GetFolder(targetPath)
currCol = 2
For Each thefile In theFolder.Files
If (InStr(1, thefile.Name, "xls", vbTextCompare) > 0 And Left(thefile.Name, 1) <> "~") Then
Workbooks.Open thefile.Path
sourceFile = ActiveWorkbook.Name
For i = 2 To 148
If Workbooks(sourceFile).Sheets("Daily").Cells(35, 1) = ThisWorkbook.ActiveSheet.Cells(i, 1) Then
ThisWorkbook.ActiveSheet.Cells(1, currCol) = Workbooks(sourceFile).Sheets("Daily").Range("A3:A3").Value
ThisWorkbook.ActiveSheet.Range(Cells(i, currCol), Cells(148, currCol)) = Workbooks(sourceFile).Sheets("Daily").Range("B35:B150").Value
currCol = currCol + 1
End If
Next i
Workbooks(sourceFile).Close
End If
Next
endtime = Now
End Sub
Thanks, all!