Nelson78
Well-known Member
- Joined
- Sep 11, 2017
- Messages
- 526
- Office Version
- 2007
Good morning everybody.
I've my workbook with a sheet named "One" with four columns, "Alpha", "Beta", "Gamma" and "Delta".
Another sheet is called "Two" where you can find a lot of columns among which "Alpha", "Beta", "Gamma" and "Delta" that could change their position every day.
Now, I need to copy the datas of the four columns from "Two to "One" with no considering the header (they are already set).
My attempt (at the moment I'm not able to exclude the headers)
Thank you.
I've my workbook with a sheet named "One" with four columns, "Alpha", "Beta", "Gamma" and "Delta".
Another sheet is called "Two" where you can find a lot of columns among which "Alpha", "Beta", "Gamma" and "Delta" that could change their position every day.
Now, I need to copy the datas of the four columns from "Two to "One" with no considering the header (they are already set).
My attempt (at the moment I'm not able to exclude the headers)
Code:
Sub Copycolumns()
Dim header As Variant
header = Array("Alpha", "Beta", "Gamma", "Delta")
Dim i As Long
For i = 0 To UBound(header)
Sheets("Two").Select
On Error GoTo ErrHandler
Cells.Find(What:=Titles(i), After:=Range("A1"), _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns).EntireColumn.Copy
On Error GoTo 0
Sheets("One").Select
Range("A1").Offset(0, i).Select
ActiveSheet.Paste
Application.CutCopyMode = False
NextOne:
Next i
Exit Sub
ErrHandler:
Resume NextOne
End Sub
Thank you.