Hello All,
Im looking for a way to import variable data from different columns in two different open workbooks to a master file. In the attached workbook I've given an example of the data in two different books on the Data1 and Data2 worksheets, and what the finished product should look like on the FinishedData sheet.
The code I'm working with is this:
Sub Data1()
Dim wb As Workbook, x As String
Dim ws As Worksheet
For Each wb In Workbooks 'loop through all open workooks
x = wb.Name
If wb.Name <> ThisWorkbook.Name And wb.Name Like "*Book1*" Then
Workbooks(x).Activate 'activate the workbook
For Each ws In wb.Worksheets 'loop through all the worksheets in that workbook
If ws.Name Like "*Sheet*" Then 'check if worksheet name contains Sheet
ws.Range("A1").CurrentRegion.Offset(1).Copy _
ThisWorkbook.Worksheets("Test").Range("A" & Rows.Count).End(xlUp).Offset(1)
Workbooks(x).Close savechanges:=False
End If
Next
End If
Next wb
End Sub
and this:
Sub Data2()
Dim wb As Workbook, x As String
Dim ws As Worksheet
For Each wb In Workbooks 'loop through all open workooks
x = wb.Name
If wb.Name <> ThisWorkbook.Name And wb.Name Like "*Book2*" Then
Workbooks(x).Activate 'activate the workbook
For Each ws In wb.Worksheets 'loop through all the worksheets in that workbook
If ws.Name Like "*Sheet*" Then 'check if worksheet name contains Sheet
ws.Range("A1").CurrentRegion.Offset(1).Copy _
ThisWorkbook.Worksheets("Test").Range("A" & Rows.Count).End(xlUp).Offset(1)
Workbooks(x).Close savechanges:=False
End If
Next
End If
Next wb
End Sub
There are two different buttons to call each macro. Of course, the current code will copy ALL of the data, and I need it to only grab a specific set of columns, preferably without using the clipboard. In the actual master file, "Test" is the worksheet name the data is copied to.
Any help would be greatly appreciated, Thanks!
Bookmarks