Closed Thread
Results 1 to 2 of 2

Search Column Headers and Copy into a Sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    02-08-2012
    Location
    London
    MS-Off Ver
    Excel 2016
    Posts
    9

    Search Column Headers and Copy into a Sheet

    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
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    02-08-2012
    Location
    London
    MS-Off Ver
    Excel 2016
    Posts
    9

    Re: Simple Help Needed: Search Column Headers and Copy into a Sheet

    Anyone at all?

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1