Hi guys,
Hope you're all well. Am trying to programme a simple Macro and was hoping you could help.
I have one file (Template) with various columns (A, B, C). I want to allow the user to specify an input file (with has some matching columns, A, Z, B, Y). I'd like the Macro to search column A, column B, column C, copy the entire column (including empty rows) and paste it in the Template file. So it will be a case of finding those 3 columns, and copying and pasting into the Template file with the same headings.
I've made a start but missing a few pieces. I've added annotations to help. Hope you can help.
Sub CopyAndPasteMatchingColumns()
' Prompt user for input file
FullFileName = Application.GetOpenFilename("Excel files (*.xl*),*.xl*", _
1, "Custom Dialog Title", , False)
' Select input file
Windows("Input.xlsx").Activate
' Filter the data I actually need (Type=Y)
Selection.AutoFilter
ActiveSheet.Range("$A$1:$E$4").AutoFilter Field:=5, Criteria1:="Y"
' Select desired column "A". Ideally I'd like to find the header, A, B C
Columns("B:B").Select
' Copy the entire column including spaces
Selection.Copy
' Select the output file
Windows("Template.xlsm").Activate
' Select the matching Column "A"
Columns("C:C").Select
' Paste it. Not sure how to avoid 1004 error
ActiveSheet.Paste
End Sub
Bookmarks