Solved

How to create multiple excel files or worksheet from single column in excel

Posted on 2014-04-14
2
997 Views
Last Modified: 2014-04-17
Hi, I am looking for a way to export multiple excel files or multiple sheets in one excel file based on a single column. Please see attached example. The "master" sheet has all the records with same schema. The data needs to be separated by the "locationid" column. The "1 export", "2 export", "3 export" and "4 export" sheets are the results of segmenting from the master sheet.

Any tips or software that can do this would be great.
sample.xlsx
0
Comment
Question by:Mark B
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 40000865
Here is a macro that uses Advanced Filter to create a list of unique items in column A, then uses AutoFilter to filter for each of those items. After each filtering step, the visible data will be copied to a new worksheet.
Sub ColumnA_Exporter()
Dim rg As Range, rgCrit
Dim ws As Worksheet
Dim crit As Variant, criteria As Variant
Application.ScreenUpdating = False
With Worksheets("master")
    Set rg = .UsedRange
    Set rgCrit = rg.Cells(1, rg.Columns.Count + 2)
    rg.Columns(1).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=rgCrit, Unique:=True
    Set rgCrit = Range(rgCrit.Cells(2, 1), .Cells(.Rows.Count, rgCrit.Column).End(xlUp))
    criteria = rgCrit.Value
    rgCrit.EntireColumn.Delete
End With

rg.Cells(1, 1).AutoFilter
For Each crit In criteria
    rg.AutoFilter Field:=1, Criteria1:=crit
    rg.Copy
    Set ws = Sheets.Add(After:=Sheets(Sheets.Count))
    ws.Paste
    ws.Name = crit & " export"
Next
rg.Cells(1, 1).AutoFilter
Application.Goto rg.Cells(1, 1)
End Sub

Open in new window

sampleQ28412675.xlsm
0
 

Author Closing Comment

by:Mark B
ID: 40008227
Thank you for the solution.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question