its weird but it worked. on anothe consolidated macro i did not have to declare the sheet. but the sheets were on all the same workbook. this macro the sheets are on different workbooks that needs to be consolidated. Chandoo's consolidated macro works but is not for dynamic range. it is strictly for fixed ranges. i was trying to modify his macro for dynamic ranges.
what about this. do i need to declare this range as well. i really appreciate your help.
TargetSh.Range(DestCell.Address).Select
below is the full macro again:
-----------------------------------
Sub GetData()
Dim strWhereToCopy As String, strStartCellColName As String
Dim strListSheet As String, ActualRow As Long, sh As Worksheet, TargetSh As Worksheet
Dim DestCell As Range, LastRow As Long
strListSheet = "List"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'Delete the sheet "SUMMARY" if it exists
Application.DisplayAlerts = False
On Error Resume Next
ActiveWorkbook.Worksheets("MasterData").Delete
On Error GoTo 0
Application.DisplayAlerts = True
On Error Resume Next
Set TargetSh = Worksheets("MasterData")
On Error GoTo 0
If TargetSh Is Nothing Then
Set TargetSh = Worksheets.Add(before:=Sheets(1))
TargetSh.Name = "MasterData"
Else
TargetSh.Cells.Clear
End If
Set DestCell = TargetSh.Range("A2")
Set DestCell = DestCell.Offset(1, 0)
On Error GoTo ErrH
Sheets(strListSheet).Select
Range("b2").Select
'this is the main loop, we will open the files one by one and copy their data into the masterdata sheet
Set currentWB = ActiveWorkbook
Do While ActiveCell.Value <> ""
strFileName = ActiveCell.Offset(0, 1)
'strCopyRange = ActiveCell.Offset(0, 2) & ":" & ActiveCell.Offset(0, 3)
'strWhereToCopy = ActiveCell.Offset(0, 4).Value
'strStartCellColName = Mid(ActiveCell.Offset(0, 5), 2, 1)
Application.Workbooks.Open strFileName, UpdateLinks:=False, ReadOnly:=True
Set dataWB = ActiveWorkbook
Set sh = Sheets("Daily Activity")
'activate daily activity sheet
Sheets("Daily Activity").Activate
'select usedrange to copy
LastRow = Sheets("Daily Activity").Range("D500").End(xlUp).Row
If LastRow > 1 Then
sh.Range("B7:Y" & LastRow).Copy
TargetSh.Range(DestCell.Address).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Set DestCell = DestCell.Offset(LastRow - 8)
End If
'activates master summary sheet
currentWB.Activate
Loop
Exit Sub
Application.DisplayAlerts = True
Application.ScreenUpdating = True
ErrH:
MsgBox "It seems some file was missing. The data copy operation is not complete."
Exit Sub
End Sub