Copy & Insert Entire Column from one sheet to another based on column header name

radeon187

New Member
Joined
Mar 25, 2020
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Hi everyone!

I'm looking for a simple VBA script that would copy entire columns based on the column header name in "Sheet 1" then insert the copied columns to the right of column header "ColumnHeaderName" in "Sheet 2". Ideally I would like to use some sort of array to define multiple column headers to copy within "Sheet 1".

Thanks in advance for any insight!
 

Some videos you may like

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,538
Office Version
  1. 2013
Platform
  1. Windows
Maybe this

VBA Code:
Sub t()
Dim ary As Variant, i As Long, fn As Range
With Sheets(1)
    ary = Application.Transpose(.Range("A1:C1").Value)
    For i = LBound(ary) To UBound(ary)
        Set fn = Sheets(2).Rows(1).Find(ary(i, 1), , xlValues)
            If Not fn Is Nothing Then
                .Columns(i).Copy
                fn.Offset(, 1).EntireColumn.Insert
            End If
    Next
End With
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,114,472
Messages
5,548,241
Members
410,824
Latest member
Bobmn4
Top