On sheet 1,in workbook1 cells A1:E1 have column headings, but no data. On sheet 1 of workbook2, the data range is A1: AC5000. I want to pick out the columns in this worksbook that match the headers on workbook1, copy and paste them under the column headers in workbook1. Can someone help me with this please
.
I found the below code
im header As Range, headers As Range
Set headers = wsCopyFrom1.Range("A1:AR1")
For Each header In headers
If GetHeaderColumn(header.Value) > 0 Then
Range(header.Offset(1, 0), header.End(xlDown)).Copy Destination:=wsCopyTo1a.Cells(2, GetHeaderColumn(header.Value))
End If
Next
End Sub
Function GetHeaderColumn(header As String) As Integer
Dim headers As Range
Set headers = wsCopyTo1a.Range("A1:E1")
GetHeaderColumn = IIf(IsNumeric(Application.Match(header, headers, 0)), Application.Match(header, headers, 0), 0)
End Function
But I am getting an error 404 message )object not defined) at Set hedares=wsCopyTo1a.Range.. bit.
I have set wsCopyto1a as a worksheet etc.
Please help!
.
I found the below code
im header As Range, headers As Range
Set headers = wsCopyFrom1.Range("A1:AR1")
For Each header In headers
If GetHeaderColumn(header.Value) > 0 Then
Range(header.Offset(1, 0), header.End(xlDown)).Copy Destination:=wsCopyTo1a.Cells(2, GetHeaderColumn(header.Value))
End If
Next
End Sub
Function GetHeaderColumn(header As String) As Integer
Dim headers As Range
Set headers = wsCopyTo1a.Range("A1:E1")
GetHeaderColumn = IIf(IsNumeric(Application.Match(header, headers, 0)), Application.Match(header, headers, 0), 0)
End Function
But I am getting an error 404 message )object not defined) at Set hedares=wsCopyTo1a.Range.. bit.
I have set wsCopyto1a as a worksheet etc.
Please help!