星期二, 十一月 01, 2011

Split an Excel File in to Many using VBA [Videos]

From chandoo.org
Split an Excel File in to Many using VBA [Videos]:

Splitting an Excel file in to many is easier than splitting bill in a restaurant among friends. All you need is advanced filters, a few lines of VBA code and some data. You can go splitting in no time.


Context:


Lets say you have lots of data like this in a file. And you want to split this in to multiple files, one per salesperson.


Splitting An Excel File in to Many using VBA - Example Data


Solution – Split Data in to Multiple Files using Advanced Filters & VBA


The process of splitting data can be broken down to 4 steps.



  1. Identify the split criteria and list down all values in a small range. In our case, we list all the salespersons names in a named range lstSalesman.

    List of all salespersons - Splitting data in to multiple files using VBA

  2. Set up advanced filters so that we can filter the data by one salesman at a time.

    Range where advanced filter criteria will be specified - Splitting data in to multiple files

  3. Now, for each salesman, apply advanced filters and set it to copy the filtered values elsewhere.

    1. Copy the filtered values

    2. Add a new workbook and paste the copied values there.

    3. Save the new workbook with a unique name

    4. Repeat the above 3 steps for each salesman



  4. That is all! You are done splitting.


Video Lesson on Splitting Data using Filters & VBA


Since splitting data in to multiple files requires a bit of macro code & advanced filter knowledge, I have created a short lesson explaining how this works. Watch it below.


[If you are not able to see the video, watch it on our Youtube Channel]



If you are new to VBA, take our crash course.


Download Split Data Example Workbook


Click here to download the split data example workbook.To use this,



  1. Save the downloaded file to any folder.

  2. Open the file and enable macros.

  3. Examine everything and when ready, click on “Extract” button.

  4. Check the folder where you saved the file and you will fine 4 new Excel workbooks named after the salespersons with the data extracted for them.


You can find the macro code in Module 1.


How do you Handle Splitting Situations?


In my work, I rarely had to split data. And whenever I had to split data, I usually copy paste the data after filtering what I want. But I can imagine many real life scenarios where you need to automate the splitting part.


How do you split data? What techniques and ideas you use to speed up the splitting process? Please share using comments.


More on Splitting & Consolidation


If you are in to splitting or combining things, we have a selection of tips & examples to help you. Check out these articles.



PS: Heck, we have even have an Excel tip to tell you how to split expenses among friends :P

PPS: You can use Pivot Table Report Filters if you want to split data in to multiple sheets.




没有评论: