I need to force-feed five columns of data from one workbook that has 15 columns into an existing sheet in another workbook that has 36 columns. The Header names of the destination sheet don't match the header names of the sheet I'm copying from, but the data is the compatible.
AlphaFrog posted this back in 2009:
[CODE}
Sub Copy_Columns()
Dim vHeader As Variant, rngFound As Range, i As Long
For Each vHeader In Array("District", "Address", "Contact Person")
Set rngFound = Sheets(1).Cells.Find(vHeader, , xlValues, xlWhole, 1, 1, 0)
i = i + 1
If Not rngFound Is Nothing Then
Range(rngFound, rngFound.End(xlDown)).Copy Destination:=Sheets(2).Cells(1, i)
End If
Next
Sheets(2).Select
Columns.AutoFit
End Sub
[/CODE]
This is very close to what I need...but the problem is, for example, that the destination workbook has the header "Location" while the workbook I'm copying from has the header "District"...but the data in the columns is the same.
I need to find the column in the destination workbook that has "Location" as header and the paste the data from the "District" Column in the workbook I'm copying from.
any help would be appreciated!
AlphaFrog posted this back in 2009:
[CODE}
Sub Copy_Columns()
Dim vHeader As Variant, rngFound As Range, i As Long
For Each vHeader In Array("District", "Address", "Contact Person")
Set rngFound = Sheets(1).Cells.Find(vHeader, , xlValues, xlWhole, 1, 1, 0)
i = i + 1
If Not rngFound Is Nothing Then
Range(rngFound, rngFound.End(xlDown)).Copy Destination:=Sheets(2).Cells(1, i)
End If
Next
Sheets(2).Select
Columns.AutoFit
End Sub
[/CODE]
This is very close to what I need...but the problem is, for example, that the destination workbook has the header "Location" while the workbook I'm copying from has the header "District"...but the data in the columns is the same.
I need to find the column in the destination workbook that has "Location" as header and the paste the data from the "District" Column in the workbook I'm copying from.
any help would be appreciated!