Option Explicit
Public Sub Compile_Workbook_Data()
Dim master_wkbk As Workbook: Set master_wkbk = ThisWorkbook
Dim master_sht As Worksheet: Set master_sht = ThisWorkbook.Worksheets("Task Tracking-Internal & Org.")
Dim current_wkbk As Workbook
Dim current_sht As Worksheet
Dim wkbk_list(1 To 3) As String
Dim x As Integer
Dim last_row As Integer
Dim last_col As Integer
wkbk_list(1) = "Sub Project_WorkBook - Core Services.xlsm"
wkbk_list(2) = "Sub Project_WorkBook - ESP2.0.xlsm"
wkbk_list(3) = "Sub Project_WorkBook - P2E.xlsm"
For x = 1 To UBound(wkbk_list)
Set current_wkbk = Workbooks.Open("D:\Delta Dental\" & wkbk_list(x))
Set current_sht = current_wkbk.Worksheets("Task Tracking-Internal & Org.")
last_row = current_sht.Cells.Find("*", searchorder:=xlByRows, SearchDirection:=xlPrevious).Row
last_col = current_sht.Cells.Find("*", searchorder:=xlByColumns, SearchDirection:=xlPrevious).Column
current_sht.Range(Cells(4, 1), Cells(last_row, last_col)).Copy
last_row = master_sht.Cells.Find("*", searchorder:=xlByRows, SearchDirection:=xlPrevious).Row
master_sht.Range("A" & last_row + 1).PasteSpecial Paste:=xlPasteValues
current_wkbk.Close False
Next x
End Sub
Im getting the following error while running the merge code:
Run-time error '1004': Method 'Range' of object '_worksheet' failed
Cells
withcurrent_sht.Range(current_sht.Cells(4, 1), current_sht.Cells(last_row, last_col)).Copy
. Also, what value islast_row
? – Shai Rado