+ Reply to Thread
Results 1 to 3 of 3

Find multiple column header, filter out other columns, and export data using a macro

Hybrid View

  1. #1
    Registered User
    Join Date
    05-17-2017
    Location
    Oklahoma
    MS-Off Ver
    2013
    Posts
    6

    Find multiple column header, filter out other columns, and export data using a macro

    Hello - I have multiple workbooks with 30+ columns in each workbook which are arranged in different orders. In each workbook are the same 5 columns scattered amongst the data. I want to create a vba, so I can open a file and:

    1.) Find the same 5 column headers in each workbook
    2.) Hide the remaining columns
    3.) Copy and paste the data as a value into a new workbook that is not connected to another data source (have had problems with data linking to other tables during copy and pasting)

    Thank you!

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Find multiple column header, filter out other columns, and export data using a macro

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,692

    Re: Find multiple column header, filter out other columns, and export data using a macro

    It does not do what you ask for, it does not hide columns, but who knows, you might be happy after all
    Make sure to change all references where required. The workbook with the code needs to be saved in the same folder as the other workbooks.
    Have a "dummy" folder to try it on and come back to let us know what needs tweaking/changing.
    Sub Get_Info()
        Dim sPath As String
        Dim sFil As String
        Dim owb As Workbook
        Dim twb As Workbook
        Dim ch
        Dim j As Long, a As Long
        With Application
            .Calculation = xlCalculationManual
            .EnableEvents = False
            .ScreenUpdating = False
        End With
        ch = Array("Header 1", "Header 2", "Header 3", "Header 4", "Header 5")
        Set twb = ThisWorkbook
        sPath = "C:\Which_Ever_Folder_Here\"
        sFil = Dir(sPath & "*.xl*")
        Do While sFil <> "" And sFil <> twb.Name
            Set owb = Workbooks.Open(sPath & sFil)
                With owb.Sheets("data")
                    For j = LBound(ch) To UBound(ch)
                        a = .Rows(1).Find(ch(j), , , 1).Column
                        .Range(.Cells(2, a), .Cells(.Cells(.Rows.Count, a).End(xlUp).Row, a)).Copy twb.Sheets("report").Cells(Rows.Count, j + 1).End(xlUp).Offset(1)
                    Next j
                End With
            owb.Close False 'Close no save
            sFil = Dir
        Loop
    
        With Application
            .Calculation = xlAutomatic
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Data Formating - Macro to copy header row and paste to multiple columns.
    By Mysore in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-01-2017, 09:57 AM
  2. Replies: 1
    Last Post: 04-30-2015, 10:01 AM
  3. [SOLVED] Macro to copy data from all columns containing a specified header to a combined column
    By Mamagregory in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 04-16-2014, 12:18 PM
  4. Macro to filter multiple columns of data to multiple work sheets
    By LISSANN in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-10-2014, 07:24 PM
  5. [SOLVED] Macro to find a column header and delete certain rows of data
    By robertguy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-17-2013, 02:10 PM
  6. [SOLVED] Macro to export column header and each row as seperate txt file
    By bhansen20 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-15-2012, 08:55 PM
  7. Replies: 2
    Last Post: 10-13-2012, 03:30 AM

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