If the "Field" and "Table" Values are Column Headers, this should work.
All Workbooks, Workbook with this code in it and the Workbooks you'll be copying from, have to be in one and the same Folder.
Ths code will copy said Columns into a Sheet named "Master"
This code will add a Sheet named "Master" into this Workbook.
Color Index for the Color Orange is 45 in this code. Change/adapt as required.
Change references if and where required.
Sub Copy_Field_And_Table_Columns()
Dim wb As String, i As Long, ii As Long, sh1 As Worksheet
Application.ScreenUpdating = False
ActiveWorkbook.Sheets.Add(After:=Sheets(Sheets.Count)).Name = "Master"
Set sh1 = ThisWorkbook.Sheets("Master")
wb = Dir(ThisWorkbook.Path & "\*")
Do Until wb = ""
If wb <> ThisWorkbook.Name Then
Workbooks.Open ThisWorkbook.Path & "\" & wb
For i = 1 To Workbooks(wb).Sheets.Count
With Workbooks(wb).Sheets(i)
For ii = 1 To .Cells(1, Columns.Count).End(xlToLeft).Column
If .Cells(1, ii).Value = "Field" Or .Cells(1, ii).Value = "Table" And .Cells(1, ii).Interior.ColorIndex = 45 Then
.Cells(1, ii).EntireColumn.Copy sh1.Cells(1, sh1.Cells(1, Columns.Count).End(xlToLeft).Column).Offset(, 1)
With sh1.Cells(1, sh1.Cells(1, Columns.Count).End(xlToLeft).Column)
.Value = .Value & " - " & Workbooks(wb).Name & " - " & Workbooks(wb).Sheets(i).Name
End With
End If
Next ii
End With
Next i
Application.CutCopyMode = False
Workbooks(wb).Close True
End If
wb = Dir
Loop
Application.ScreenUpdating = True
End Sub
Please use code tags when you put code in your Post. Peruse the Forum Rules. That's why we have them.
Bookmarks