OK so I have tried everything I can think of to modify this macro I pulled from the net but I keep getting errors. I don’t know where I am going wrong in addition to my limited knowledge of coding macros has really put me in a bind. I need this macro to prompt me to select a workbook(s) then copy everything on Sheet2 to my master workbook until all of the source workbooks have been processed into the master.
Here is my code. I have reverted it back to the original I copied from the net because I butchered the original too much.
I have also included my sample data.
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),
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, "AB").End(xlUp).Row
Cells(Rows.Count, "AD").Select
Selection.Copy
If LastRow >= StartRow Then
With SrcWkb.Worksheets(2)
DstWks1.Cells(R, C).Resize(LastRow - StartRow + 1, 1).Value = _
.Range(.Cells(StartRow, "AD"), .Cells(LastRow, "AD")).Value
Sheets(1).Select
ActiveSheet.Paste
End With
End If
LastRow = SrcWkb.Worksheets(1).Cells(Rows.Count, "AD").End(xlUp).Row
If LastRow >= StartRow Then
With SrcWkb.Worksheets(1)
DstWks2.Cells(R, C).Resize(LastRow - StartRow + 1, 1).Value = _
.Range(.Cells(StartRow, "AD"), .Cells(LastRow, "AD")).Value
End With
End If
C = C + 1
SrcWkb.Close SaveChanges:=False
''SrcWkb.Close''
Next wkbname
End Sub
UNSPSC_v14_0801.xlsUNSPSC_v15_1101.xlsMaster.xlsx
Bookmarks