Hi All,
I'm attempting to copy data from one work book to another. The column names in the header (Row 1) that have the data I want will always be the same, but the column order will be variable. There are many columns in the data sheet but I'm only looking for a few columns out of many.
What I have so far is this:
Sub Test
Dim ws As Worksheet
Exam1 = Application.Match("Example 1", Rows("1:1"), 0)
Exam2 = Application.Match("Example 2", Rows("1:1"), 0)
Exam3 = Application.Match("Example 3", Rows("1:1"), 0)
ws.Columns(Exam1).Copy _
Destination:=ThisWorkbook.Worksheets("Sheet1").Range("A2")
ws.Columns(Exam2).Copy _
Destination:=ThisWorkbook.Worksheets("Sheet1").Range("B2")
ws.Columns(Exam3).Copy _
Destination:=ThisWorkbook.Worksheets("Sheet1").Range("C2")
End Sub
Which will copy the entire column, but I already have specific headers and formatting in the destination workbook, so I only want the variable data in each column to be copied.
What I would normally use copy data out of a column is this:
ws.Range("B2", Range("B" & Rows.count).End(xlUp)).Copy _
ThisWorkbook.Worksheets("Sheet1")Range("A" & Rows.count).End(xlUp).Offset(1)
Which is works great when I know which order the columns will be in (Column B for example), which is not the casecurrently.
Any help would be greatly appreciated, thanks!
Bookmarks