Hi, I have one sheet in my file named "G2N" which has column headers in a fixed order and i want to populate the rows under those columns with data from another sheet which i is called "BDOG2N".
The column headers are not in the same order in the different sheets and "BDOG2N" might have column headers that are not in the "G2N" sheet and vice versa.
I have tried to do this via VBA with the find function and running into a problem when I have a header in the "BDOG2N" which doesnt exist in the "G2N" sheet. If this happens, then i want to print/write the column header name somewhere so I can investigate this column manually once makro has completed.
Thank you
Code
Sub G2N()
MF = ActiveWorkbook.Name
Workbooks(MF).Activate
BDOG2N = ActiveSheet.Name
Sheets(BDOG2N).Select
Cells(1, 1).Select
Range(Selection, Selection.End(xlDown)).Select
MyRows = Selection.Count
Cells(1, 1).Select
Range(Selection, Selection.End(xlToRight)).Select
MyCols = Selection.Count
For i = 1 To MyCols
Sheets(BDOG2N).Select
MyHeader = Cells(1, i)
Range(Cells(2, i), Cells(MyRows, i)).Select
Selection.Copy
Sheets("G2N").Select
Cells(1, 1).Select
Range("1:1").Find(what:=MyHeader, After:=ActiveCell, LookIn:=xlFormulas, _
lookat:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
MyCurrentCol = ActiveCell.Column
Cells(2, MyCurrentCol).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Next i
End Sub
Display More