I have a below code which is copy data from multiple workbooks into 1 workbook.sheet1 the code gives me message to press yes for further workbook and then further if the folder have 10 workbook then it will ask 9 times. I want to run this code without this YES option.
One more thing that is when i run this code then it should ask me to select the folder to copy the data from multiple workbooks.
any help would be appreciated.
Code
Sub FirstRows()
Application.ScreenUpdating = False
Dim MyFolder As String, MyFile As String, wbSrc As Workbook
Set shtDest = ThisWorkbook.Sheets("Sheet1")
ChDrive "Z:"
ChDir "C:\Users\shazir\Downloads\Example"
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Please select a folder"
.Show
.AllowMultiSelect = False
MyFolder = .SelectedItems(1) & "\"
End With
MyFile = Dir(MyFolder)
Do While MyFile <> ""
Set wbSrc = Workbooks.Open(Filename:=MyFolder & "\" & MyFile)
Sheets("Masterbook").UsedRange.Copy
With shtDest
.Cells(.Rows.Count, "A").End(xlUp).Offset(5).PasteSpecial xlPasteFormats
.Cells(.Rows.Count, "A").End(xlUp).Offset(5).PasteSpecial xlPasteValues
End With
wbSrc.Close SaveChanges:=True
MyFile = Dir
Application.ScreenUpdating = True
Loop
End Sub
Display More