Results 1 to 3 of 3

Thread: Copy Data From Multiple Workbooks To A Master Workbook

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    Copy Data From Multiple Workbooks To A Master Workbook

    Hi all

    I have an excel (2010) workbook which contains 1 worksheet called MASTER. This sheet has the headers starting in A1 through E1:

    Date
    Company Name
    Contact
    TorV
    Details

    I want a VBA script that will run from the MASTER worksheet and allow me to select multiple workbooks in a folder and copy the data (from ROW 22) until LAST ROW and add it to the worksheet called MASTER.

    I already have a VBA script (shown below so that other users can use) which allows me to select multiple workbooks in a folder and pull out individual cells data but I need to change the script to pull out ROWS data as per the paragraph above.

    I have just got back off holiday and my mind is blank as to how to change the script

    Many Thanks


    Craig:

    Code:
    Sub BulkImport()
       Dim InFileNames As Variant
       Dim OutFileName As String
       Dim fCtr As Long
       Dim tempWkbk As Workbook
       Dim consWks As Worksheet
       Dim destCell As Range
       Dim myRow As Long
       Dim total As Long
       Dim LastRow As Long
       Set consWks = ActiveWorkbook.Sheets(1)
       LastRow = consWks.Range("A65536").End(xlUp).Row
       InFileNames = Application.GetOpenFilename _
       (FileFilter:="Excel Files, *.xl*", MultiSelect:=True)
       Application.ScreenUpdating = False
       If IsArray(InFileNames) Then
          For fCtr = LBound(InFileNames) To UBound(InFileNames)
             Set tempWkbk = Workbooks.Open(Filename:=InFileNames(fCtr))
             consWks.Range("A" & fCtr + LastRow).Value = tempWkbk.Worksheets(1).Range("A22").Value
             consWks.Range("B" & fCtr + LastRow).Value = tempWkbk.Worksheets(1).Range("B22").Value
             consWks.Range("C" & fCtr + LastRow).Value = tempWkbk.Worksheets(1).Range("C22").Value
             consWks.Range("D" & fCtr + LastRow).Value = tempWkbk.Worksheets(1).Range("D22").Value
             consWks.Range("E" & fCtr + LastRow).Value = tempWkbk.Worksheets(1).Range("E22").Value
           ActiveWorkbook.Close
          Next fCtr
       Else
          MsgBox "No file selected"
       End If
       With Application
          .StatusBar = False
          .ScreenUpdating = True
       End With
    End Sub
    Last edited by Excel Fox; 05-28-2013 at 04:31 PM. Reason: Code Tags Added

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    try this..

    Code:
    Sub BulkImport()
    
       Dim InFileNames As Variant
       Dim fCtr As Long
       Dim tempWkbk As Workbook
       Dim consWks As Worksheet
       Set consWks = ThisWorkbook.Sheets(1)
       InFileNames = Application.GetOpenFilename _
       (FileFilter:="Excel Files, *.xl*", MultiSelect:=True)
       Application.ScreenUpdating = False
       If IsArray(InFileNames) Then
          For fCtr = LBound(InFileNames) To UBound(InFileNames)
            With Workbooks.Open(Filename:=InFileNames(fCtr))
                .Sheets(1).Range("A22:E" & .Sheets(1).Range("A" & .Sheets(1).Rows.Count).End(xlUp).Row).Copy consWks.Range("A" & consWks.Rows.Count).End(xlUp)(2)
                .Close 0
            End With
          Next fCtr
       Else
          MsgBox "No file selected"
       End If
       With Application
          .StatusBar = False
          .ScreenUpdating = True
       End With
       
    End Sub
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    Talking Copying Rows From Multiple Workbooks Sorted!!!

    Thank you Excel Fox for the script - which works exactly as I envisaged it would.

    I also realise that I was declaring names that were not needed in the original script. I use the original script for copying data from Excel quote Forms onto an excel master quotation log.

    Thank you again.

Similar Threads

  1. Replies: 1
    Last Post: 06-07-2013, 10:32 AM
  2. Replies: 1
    Last Post: 05-09-2013, 08:56 AM
  3. Consolidate multiple workbooks from a folder into one master file VBA
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 4
    Last Post: 02-26-2013, 09:00 PM
  4. Replies: 2
    Last Post: 11-08-2012, 01:15 PM

Tags for this Thread

Posting Permissions

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