Tim Hanson
Member
Hello
I am tring to find a column by the header name then copy the UsedRange of the column to the last column + 1
I am not getting this part right I think ".UsedRange.Range(c.Address).Copy"
Thank you for your consideration.
I am tring to find a column by the header name then copy the UsedRange of the column to the last column + 1
I am not getting this part right I think ".UsedRange.Range(c.Address).Copy"
Thank you for your consideration.
Code:
Sub CopyColToLastCol()
Dim lastHeaderCol As Long
Dim lRow As Long
Dim rNameHeader As Range
Set ws = ActiveWorkbook.Sheets("LI - names fixed")
With ws.UsedRange
'determine last filled cell in first row
lastHeaderCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
lRow = .Range("A" & .Rows.Count).End(xlUp).Row
Set c = .Find("email address", LookIn:=xlValues)
If Not c Is Nothing Then
.UsedRange.Range(c.Address).Copy _
Destination:=.Range(Cells(1, lastHeaderCol + 1), Cells(lRow, lastHeaderCol + 1))
End If
End With
End Sub