I'm still new to VBA and I'm a bit lost on how to solve this particular issue.
I have several worksheets within 1 workbook. The goal is to copy data from each worksheet based on the column headings, since not all of the column headings are uniform across all sheets.
For ex:
The Master Sheet has 6 column headings which I'd like to pull.
Sheet 1 has 8 column headings, the values for some columns within this are blank.
Sheet 2 has 7 column headings.
Sheet 3 has 10 column headings, etc.
My goal is to go to each sheet, have it loop through each column heading and copy/paste the data into the Master sheet if the column heading matches.
I don't know how to get it to look for the last row and copy the whole column based on the heading.
An example of code I've pieced together below:
Sub MasterCombine()
Worksheets("Master").Activate
Dim ws As Worksheet
Set TH = Range("A1:F1")
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "Master" And ws.Range("A8").Value <> "" Then
ws.Select
Range("A8").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Worksheets("Master").Activate
For Each cell In TH
If cell.Value = "Subject" Then
cell.EntireColumn.Copy
End If
The problem with the above is that it copies the entire range but doesn't filter out column headings that aren't in the Master sheet.
Any help would be appreciated.