Results 1 to 4 of 4

loop through files find columns and copy/paste them as columns in master workbook

Threaded View

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

    Re: loop through files find columns and copy/paste them as columns in master workbook

    If the "Field" and "Table" Values are Column Headers, this should work.

    All Workbooks, Workbook with this code in it and the Workbooks you'll be copying from, have to be in one and the same Folder.
    Ths code will copy said Columns into a Sheet named "Master"
    This code will add a Sheet named "Master" into this Workbook.
    Color Index for the Color Orange is 45 in this code. Change/adapt as required.
    Change references if and where required.

    Sub Copy_Field_And_Table_Columns()
        Dim wb As String, i As Long, ii As Long, sh1 As Worksheet
        Application.ScreenUpdating = False
        ActiveWorkbook.Sheets.Add(After:=Sheets(Sheets.Count)).Name = "Master"
        Set sh1 = ThisWorkbook.Sheets("Master")
        wb = Dir(ThisWorkbook.Path & "\*")
        Do Until wb = ""
            If wb <> ThisWorkbook.Name Then
                Workbooks.Open ThisWorkbook.Path & "\" & wb
                For i = 1 To Workbooks(wb).Sheets.Count
                    With Workbooks(wb).Sheets(i)
                        For ii = 1 To .Cells(1, Columns.Count).End(xlToLeft).Column
                            If .Cells(1, ii).Value = "Field" Or .Cells(1, ii).Value = "Table" And .Cells(1, ii).Interior.ColorIndex = 45 Then
                                .Cells(1, ii).EntireColumn.Copy sh1.Cells(1, sh1.Cells(1, Columns.Count).End(xlToLeft).Column).Offset(, 1)
                                With sh1.Cells(1, sh1.Cells(1, Columns.Count).End(xlToLeft).Column)
                                    .Value = .Value & " - " & Workbooks(wb).Name & " - " & Workbooks(wb).Sheets(i).Name
                                End With
                            End If
                        Next ii
                    End With
                Next i
                Application.CutCopyMode = False
                Workbooks(wb).Close True
            End If
            wb = Dir
        Loop
        Application.ScreenUpdating = True
    End Sub
    Please use code tags when you put code in your Post. Peruse the Forum Rules. That's why we have them.
    Last edited by jolivanes; 07-16-2018 at 11:48 PM. Reason: Request using code tags

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Copy data from multiple files, then paste to master workbook.
    By TonyPepper in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-06-2016, 06:35 AM
  2. [SOLVED] Problem looping through multiple files to copy/paste into master workbook
    By shoes1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-07-2015, 02:46 PM
  3. [SOLVED] Copy certain columns from all the files and paste in a Summary workbook
    By vignesh rocks in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 11-19-2012, 09:33 AM
  4. Update master file columns with columns from slave files
    By underskinned in forum Excel General
    Replies: 1
    Last Post: 09-11-2012, 12:21 PM
  5. Replies: 2
    Last Post: 09-11-2012, 09:42 AM
  6. Loop Through and Copy CSV Files to Master Workbook
    By sweetnumb in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-12-2012, 06:25 AM
  7. Loop workbook find and copy data columns
    By Zaeguzah in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-22-2010, 06:10 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