+ Reply to Thread
Results 1 to 10 of 10

Splitting one file into many with fewer columns

  1. #1
    Registered User
    Join Date
    07-10-2011
    Location
    Salt Lake City, UT
    MS-Off Ver
    Excel 2003
    Posts
    8

    Splitting one file into many with fewer columns

    Hi everyone. I don't know if this can be done with or without VBA and a macro. I have a spreadsheet, attached below, which has a number of statistics and then columns with measures of success with 0s or 1s. I need to create multiple spreadsheets, each that have all of the statistics, but only one measure of success at the end. I would just copy and paste, but I need to do this for around 50 files. Any help?

    Thanks!
    Attached Files Attached Files
    Last edited by andylarsen; 07-11-2011 at 11:11 PM.

  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: Splitting one file into many with fewer columns

    So the files created would have the following columns:

    File 1 = Columns A,B,C,D
    File 2 = Columns A,B,C,E
    File 3 = Columns A,B,C,F
    File 4 = Columns A,B,C,G

    Correct?


    What would be the naming convention of these files?

    File 1 = CareerG.xls
    File 2 = CareerMP.xls
    File 3 = CareerFGA-G.xls
    File 4 = CareerFGP-G.xls
    etc...?
    _________________
    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
    07-10-2011
    Location
    Salt Lake City, UT
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Splitting one file into many with fewer columns

    Quote Originally Posted by JBeaucaire View Post
    So the files created would have the following columns:

    File 1 = Columns A,B,C,D
    File 2 = Columns A,B,C,E
    File 3 = Columns A,B,C,F
    File 4 = Columns A,B,C,G

    Correct?


    What would be the naming convention of these files?

    File 1 = CareerG.xls
    File 2 = CareerMP.xls
    File 3 = CareerFGA-G.xls
    File 4 = CareerFGP-G.xls
    etc...?
    You have the right idea, except instead of only A,B,C included on every file, I need every column from A-AO. Naming convention should append the name of the success measure at the end of the file. So:

    File 1 = Columns A,B,C...,AM,AN,AOAP
    File 2 = Columns A,B,C...,AM,AN,AOAQ
    File 3 = Columns A,B,C...,AM,AN,AOAR
    File 4 = Columns A,B,C...,AM,AN,AOAS
    ...

    And file names should be
    File 1 = pareddown-centers-allmos-post2007-draftednominal.xls
    File 2 = pareddown-centers-allmos-post2007-playedInNBA.xls
    File 3 = pareddown-centers-allmos-post2007-scored10PPGRookieYear.xls
    File 4 = pareddown-centers-allmos-post2007-NBACareerPPG.xls
    etc.

    Does that make sense?

    Andy

  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: Splitting one file into many with fewer columns

    You can't have percentage symbol in file names, so those will be stripped...see BP1...

  5. #5
    Registered User
    Join Date
    07-10-2011
    Location
    Salt Lake City, UT
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Splitting one file into many with fewer columns

    Okay, I'll just find and replace those.

  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: Splitting one file into many with fewer columns

    Give this a try:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-10-2011
    Location
    Salt Lake City, UT
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Splitting one file into many with fewer columns

    That works exactly as desired, thanks!

    A couple of questions:

    1. If I want to save them as CSVs, do I simply change the part where it says .xls to .csv? Or is it more difficult than that?
    2. Other files I'm using this code will have other numbers of columns that I want to keep, for example, from A:AX. Is changing that a matter of changing the part where it says "Range("A:AO")"? Or do I have to change that column count as well?

    Thanks again!

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

    Re: Splitting one file into many with fewer columns

    You would need to change that line of code to indicate the main columns to copy, correct!

    But also notice this line of code which is where we add the additional "stat" column:
    Please Login or Register  to view this content.
    This code was designed to start after your original "main" data columns, column 42 is AP, and it increments up from there. Whatever you change the range of main columns to, edit that 42 to start at the first "stat" column.

    To save as CSV, you might just edit this one parameter:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    07-10-2011
    Location
    Salt Lake City, UT
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Splitting one file into many with fewer columns

    Thanks again, it all worked great!

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

    Re: Splitting one file into many with fewer columns

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

+ 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