+ Reply to Thread
Results 1 to 6 of 6

Macro to copy data from multiple files to one master

  1. #1
    Registered User
    Join Date
    06-01-2012
    Location
    denver
    MS-Off Ver
    Excel 2007
    Posts
    5

    Post Macro to copy data from multiple files to one master

    Hi All,

    I am not a very expert Excel user and dont have to use much in my everyday work, but for my current project I have to consolidate data from 500 plus files into one file, can anyone help. I am trying to use the Macro for the first time.

    here is the scenario;

    I have all my .csv files in one folder. I have the master file (empty but just with headers) in the same directory (For ex: C\temp)

    All my csv files have data in the range (A3:AW3), few of my .csv will have A3 and B3 blank so for those the data will be available only through C3:AW3.

    All the csv files have one sheet with naming convention 2_10_100_1G_AutoReport2012-05-*

    How do I proceed to copy all that data into one file.

    Help much appreciated.

    Thanks
    D

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to copy data from multiple files to one master

    'CSVs To One Sheet (Stacked)
    To get you started, here's a macro for importing all CSV files in a folder into a single Excel sheet, each CSV filename will be listed on the sheet next to the data that it came from.
    CSVs to 1 Sheet - Part 1



    You'll want to edit this line of code:
    Please Login or Register  to view this content.
    ...perhaps to:

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    06-01-2012
    Location
    denver
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Macro to copy data from multiple files to one master

    Hi JB,
    Thanks for the reply, appreciate a lot,

    I commented the lines that adds the CSV names, as i do not need them in my final sheet, but for some reason when I run the Macro it gives me

    "Subscription Out of Range Error" and when I go into Debug mode it highlights the beow line of code.

    : Set wsMstr = ThisWorkbook.Sheets("SLC Master")

    Now like I said, all my csv files and master csv file is in the same folder. Master CSV file hs all the heading and the Sheet Name is Master SLC.

    What am I doing wrong here.

    Here is the code
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 06-06-2012 at 06:14 PM. Reason: Added Code Tags

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to copy data from multiple files to one master

    Please Login or Register  to view this content.
    An error on that line of code could mean:

    1) The sheet doesn't exist in the workbook where the macro was installed
    2) The sheet exists but is misspelled in some way... missing or extra spaces, maybe?

  5. #5
    Registered User
    Join Date
    06-01-2012
    Location
    denver
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Macro to copy data from multiple files to one master

    Sorry about the rules, I thought the thread was most closest to what I was looking for but will keep that in mind.

    So Far,

    I have 500 plus files, where some start with Column A Row 1 as "lost frames" header with data and other start with Column A as Row 1"sync loss second", Column B Row 1 as "Link Loss Seconds and then Column C as "lost frames". How do I insert two blank rows at the starting to all the files that has Column A as "lost frames".

    if I do this, then I am able to add columns in front of Column A where Column A1 valus is lost frames.

    Please Login or Register  to view this content.
    But for other files where the 1st and 2nd Column are Column A as "sync loss second", Column B as "Link Loss Seconds, I want to use the range that only checks lost frames for column A1. if not do not do anything. Because the above code will still search for Row 1 for lost frames string and will add two additional rows in front since all the files do have the lost frames in either A1 or C1

    Thanks
    Deepak
    Last edited by deepakgautam; 06-06-2012 at 04:20 PM.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to copy data from multiple files to one master

    Your sample code seems correct. maybe:

    Please Login or Register  to view this content.

+ Reply to 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