Ok I've come up with something for you to try. All the details are in a textbox for you to read. Try to do exactly what they say & fingers crossed, it'll work.
Cheers
Phil
Option Explicit
Sub DataImporter()
Dim WkBk2Open As String, FolderPath As String
Dim Wb1 As String, Wb2 As String, Wb3 As String, Wb4 As String
Dim Wsht As Worksheet, Wsht0 As Worksheet
Dim CopyRange As Range
Dim LastCol As Long, LastRow As Long, X As Long
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
FolderPath = VBA.Environ("UserProfile") & "\Documents\Reports\65MHz Report\"
' FolderPath = VBA.Environ("UserProfile") & "\Documents\"
Wb1 = Dir$(FolderPath & "65MHz_Major_Milestone_DRT.xlsxm")
Wb2 = Dir$(FolderPath & "IM_Milestones_Rev031414_1407333437135.xlsx")
Wb3 = Dir$(FolderPath & "Supply_Details_-_65MHz.xlsx")
Wb4 = Dir$(FolderPath & "Consolidated Locked List.xlsx")
' Wb1 = Dir$(FolderPath & "Book1.xlsb")
' Wb2 = Dir$(FolderPath & "Book2.xlsb")
' Wb3 = Dir$(FolderPath & "Book3.xlsb")
' Wb4 = Dir$(FolderPath & "Book4.xlsb")
On Error GoTo ErrorOut
For X = 1 To 4
Select Case X
Case 1
WkBk2Open = Wb1
Set Wsht = ThisWorkbook.Sheets(3)
Case 2
WkBk2Open = Wb2
Set Wsht = ThisWorkbook.Sheets(4)
Case 3
WkBk2Open = Wb3
Set Wsht = ThisWorkbook.Sheets(5)
Case 4
WkBk2Open = Wb4
Set Wsht = ThisWorkbook.Sheets(6)
Set Wsht0 = ThisWorkbook.Sheets(7)
Case Else
End Select
Workbooks.Open (WkBk2Open)
LastCol = Workbooks(WkBk2Open).Sheets(1).Rows(20).Find(what:="*", _
LookIn:=xlValues, lookat:=xlPart, searchorder:=xlByColumns, _
searchdirection:=xlPrevious, MatchCase:=False, searchformat:=False).Column
LastRow = Workbooks(WkBk2Open).Sheets(1).Columns(1).Find(what:="*", _
LookIn:=xlValues, lookat:=xlPart, searchorder:=xlByRows, _
searchdirection:=xlPrevious, MatchCase:=False, searchformat:=False).Row
Set CopyRange = Workbooks(WkBk2Open).Sheets(1).Range(Workbooks(WkBk2Open) _
.Sheets(1).Cells(1, 1), Workbooks(WkBk2Open).Sheets(1).Cells(LastRow, LastCol))
DoEvents
CopyRange.Copy Wsht.Cells(1, 1)
If X = 4 Then
LastCol = Workbooks(WkBk2Open).Sheets(2).Rows(20).Find(what:="*", _
LookIn:=xlValues, lookat:=xlPart, searchorder:=xlByColumns, _
searchdirection:=xlPrevious, MatchCase:=False, searchformat:=False).Column
LastRow = Workbooks(WkBk2Open).Sheets(2).Columns(1).Find(what:="*", _
LookIn:=xlValues, lookat:=xlPart, searchorder:=xlByRows, _
searchdirection:=xlPrevious, MatchCase:=False, searchformat:=False).Row
Set CopyRange = Workbooks(WkBk2Open).Sheets(2).Range(Workbooks(WkBk2Open) _
.Sheets(2).Cells(1, 1), Workbooks(WkBk2Open).Sheets(2).Cells(LastRow, LastCol))
DoEvents
CopyRange.Copy Wsht0.Cells(1, 1)
Else: End If
Workbooks(WkBk2Open).Close False
LastCol = 0
LastRow = 0
Set CopyRange = Nothing
Next X
With Application
.Calculation = xlCalculationAutomatic
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = True
End With
Exit Sub
ErrorOut:
MsgBox " An Error Occured On" & cbcrlf _
& " The " & X & "th Loop" & cbcrlf _
& " Macro Will Now Exit"
With Application
.Calculation = xlCalculationAutomatic
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = True
End With
Exit Sub
End Sub
Bookmarks