I have the attached code to select a set of files to copy data from into the tabs of my workbook. However, I get a type mismatch error 15 if I change my mind and cancel the file selection. Unsuccessfuly tried to add code to check this. Appreciate any help
Sub CopyPasteData()
Dim i As Long
Dim arraySheets As Variant
Dim myFile As Variant
Dim sourceWbk As Workbook
Dim destWbk As Workbook
Application.ScreenUpdating = False
continue:
arraySheets = Array("Notifications", "Orders", "Operations", "Schedule")
Set destWbk = ThisWorkbook
myFile = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls*), *.xls*", Title:="Select a File", MultiSelect:=True)
For i = LBound(arraySheets) To UBound(arraySheets)
If UBound(myFile) = 4 Then
If Sheets(arraySheets(i)).Range("A1") <> "" Then Sheets(arraySheets(i)).Cells.ClearContents
If Sheets(arraySheets(i)).Range("A1") = "" Then
Set sourceWbk = Workbooks.Open(myFile(i + 1))
ActiveSheet.Cells.Copy
destWbk.Sheets(arraySheets(i)).Range("A1").PasteSpecial
Application.CutCopyMode = False
sourceWbk.Close True
Set sourceWbk = Nothing
End If
Else
MsgBox "Please select all 4 data files at once!", vbInformation, "Select Multi Files"
GoTo continue
End If
Next i
MsgBox "All data has been copied!", vbInformation, "Action Complete"
Set destWbk = Nothing
Sheet4.Activate
Application.ScreenUpdating = True
End Sub
Sub CopyPasteData()
Dim i As Long
Dim arraySheets As Variant
Dim myFile As Variant
Dim sourceWbk As Workbook
Dim destWbk As Workbook
Application.ScreenUpdating = False
continue:
arraySheets = Array("Notifications", "Orders", "Operations", "Schedule")
Set destWbk = ThisWorkbook
myFile = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls*), *.xls*", Title:="Select a File", MultiSelect:=True)
For i = LBound(arraySheets) To UBound(arraySheets)
If UBound(myFile) = 4 Then
If Sheets(arraySheets(i)).Range("A1") <> "" Then Sheets(arraySheets(i)).Cells.ClearContents
If Sheets(arraySheets(i)).Range("A1") = "" Then
Set sourceWbk = Workbooks.Open(myFile(i + 1))
ActiveSheet.Cells.Copy
destWbk.Sheets(arraySheets(i)).Range("A1").PasteSpecial
Application.CutCopyMode = False
sourceWbk.Close True
Set sourceWbk = Nothing
End If
Else
MsgBox "Please select all 4 data files at once!", vbInformation, "Select Multi Files"
GoTo continue
End If
Next i
MsgBox "All data has been copied!", vbInformation, "Action Complete"
Set destWbk = Nothing
Sheet4.Activate
Application.ScreenUpdating = True
End Sub