A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
If I am interpreting correctly what you are attempting to do then like the code below.
In the following line of your code Rows.Count is referencing the ActiveSheet; not necessarily Worksheet Register.
LastRow = Worksheets("Register").Cells(Rows.Count, 1).End(xlUp).Offset(1).Row
Should be like the following line but personally I prefer to use With / End With as per my example code.
LastRow = Worksheets("Register").Cells(**Worksheets("Register").**Rows.Count, 1).End(xlUp).Offset(1).Row
Note that the space and underscore at the end of a line is a line break in an otherwise single line of code. (Used below after Copy).
The bold code in the Destination was the major correction to your code..
Sub CopysourcedatetoRegister()
Dim LastRow As Long
With Worksheets("Register")
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Offset(1).Row
End With
Dim header As Range, headers As Range
Set headers = Worksheets("source data").Range("A1:v1")
For Each header In headers
If GetHeaderColumn(header.Value) > 0 Then
Range(header.Offset(1, 0), header.End(xlDown)).Copy _
Destination:=Worksheets("register").Cells(LastRow, GetHeaderColumn(header.Value))
End If
Next
End Sub
Function GetHeaderColumn(header As String) As Integer
Dim headers As Range
Set headers = Worksheets("register").Range("A1:Z1")
GetHeaderColumn = IIf(IsNumeric(Application.Match(header, headers, 0)), Application.Match(header, headers, 0), 0)
End Function