+ Reply to Thread
Results 1 to 3 of 3

Open a file and copy data into multiple files

  1. #1
    Registered User
    Join Date
    10-11-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    21

    Open a file and copy data into multiple files

    Hi,

    I have a file (Source) which has 3 columns of importance :- Codes, Revenue and Expenses.

    For each code, there exists a file on a drive (with some characters before and after) e.g:
    Code = 3034901; File name = 2010_Q2_3034901.xls

    There are about 500 codes and accordingly 500 files (There could be a mismatch but we can handle that exception later on as we proceed)

    The idea is to open the Source file, parse through each code, open the corresponding file, check whether a particular (B16) within the opened file is not empty, and if not, update (Copy) two cells (F31 and B48) with corresponding data from the Revenue and expenses column of the source file. Do this until all the codes of the source file are parsed through.

    I want to write a macro for the same and know nothing about macros. All help will be appreciated.

    Thanks

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Open a file and copy data into multiple files

    Not a five minute task.

    Given that the files don't map directly to the codes, I think you'd first need to create a list of all the files in the directory (and they'd really need to be in the same directory). Then you can extract the code from the filename and create a lookup table.

    Once that table is set up, probably as part of a Workbook Open event, you can process the codes. For each code, lookup the code in the table and identify the relevant file.

    It's possible to extract data from a closed file so read B16 and, if it is not blank, open the file, update it, save it and close it.

    Could there be more than one file for a given code? As the prefix is date related, the implication is there could be several.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    10-11-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    21

    Re: Open a file and copy data into multiple files

    For each code there is only one file in the directory but that file could have either of the following names:

    2010q3_<code>.xls
    2010q3_<code>s.xls
    2010q3_<code>Contr.xls
    2010q3_<code>sContr.xls

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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