Lastrow Should be "D". Here is what I have now and it does run through the sheets but it doesnot paste the values in the master fille.
Sub Collect_Data()
Dim C As Long
Dim DstWks1 As Worksheet
Dim DstWks2 As Worksheet
Dim LastRow As Long
Dim R As Long
Dim SrcWkb As Workbook
Dim StartRow As Long
Dim wkbname As Variant
Dim xlsFiles As Variant
'Starting column and row for the destination workbook
C = 1
R = 1
'Set references to destination workbook worksheet objects
Set DstWks1 = ThisWorkbook.Worksheets("Sheet1")
Set DstWks2 = ThisWorkbook.Worksheets("Sheet2")
'Starting row on source worksheet
StartRow = 1
'Get the workbooks to open GetOpenFilename
'xlsFiles = Application.FileDialog(FileFilter:="Excel files (*.xls*),*.xls*", MultiSelect:=True) 'Excel files (*.xls),
xlsFiles = Application.GetOpenFilename(FileFilter:="Excel files (*.xls*),*.xls*", MultiSelect:=True) 'Excel files (*.xls),
Application.AskToUpdateLinks = False
If VarType(xlsFiles) = vbBoolean Then Exit Sub
'Loop through each workbook and copy the data to this workbook
For Each wkbname In xlsFiles
Set SrcWkb = Workbooks.Open(Filename:=wkbname, ReadOnly:=True)
LastRow = SrcWkb.Worksheets(2).Cells(Rows.Count, "D").End(xlUp).Row
Cells(Rows.Count, "D").Select
Selection.Copy
If LastRow >= StartRow Then
With SrcWkb.Worksheets(2)
DstWks1.Cells(R, C).Resize(LastRow - StartRow + 1, 1).Value = _
.Range(.Cells(StartRow, "A"), .Cells(LastRow, "D")).Value
Sheets(1).Select
ActiveSheet.Paste
End With
End If
LastRow = SrcWkb.Worksheets(1).Cells(Rows.Count, "D").End(xlUp).Row
If LastRow >= StartRow Then
With SrcWkb.Worksheets(1)
DstWks2.Cells(R, C).Resize(LastRow - StartRow + 1, 1).Value = _
.Range(.Cells(StartRow, "A"), .Cells(LastRow, "D")).Value
End With
End If
C = C + 1
SrcWkb.Close SaveChanges:=False
''SrcWkb.Close''
Next wkbname
End Sub
Bookmarks