+ Reply to Thread
Results 1 to 6 of 6

Macro to copy entries from a file (if they satisfy a condition) and save in a new file

  1. #1
    Registered User
    Join Date
    05-08-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    6

    Macro to copy entries from a file (if they satisfy a condition) and save in a new file

    Hi,

    I need to copy entries from one consolidated file and split them into different files. I have attached the file containing my data.

    What I need to do is copy all the entries for one country and create & save (as country name) a new excel file containing all the entries for that country. My data is all sorted by country name, so a simple 'if' condition to copy all the cells till the country name changes should work. I would also need the heading row (1).

    Path to save: C:\Documents and Settings\prabhakarc\Desktop\Caleb

    Some ideas that I have: I have created a blank template file with the headings with the name Country_Data, so pasting the copied data into this file and Saving As 'Country name' copied from the consolidated file might work?

    Appreciate the help in advance!

    Thanks,
    Caleb
    Attached Files Attached Files

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Macro to copy entries from a file (if they satisfy a condition) and save in a new file

    Try this code
    Please Login or Register  to view this content.
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    05-08-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Macro to copy entries from a file (if they satisfy a condition) and save in a new file

    Thanks! I will try this out!

  4. #4
    Registered User
    Join Date
    05-08-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Macro to copy entries from a file (if they satisfy a condition) and save in a new file

    Hi arlu1201,

    This is working great for the first Country (Argentina), however I want it to repeat the same operation for all the countries in the file.

    How do I edit this code to do that?

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Macro to copy entries from a file (if they satisfy a condition) and save in a new file

    I tested it at my end and it works fine. Ensure that you put the macro in the file which contains the data.

    You do not have to edit it. It will give you the output for all the countries.

  6. #6
    Registered User
    Join Date
    05-08-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Macro to copy entries from a file (if they satisfy a condition) and save in a new file

    Thanks! I tried it again and it worked this time. Trying the macro on a larger data set now.

+ 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