?
Solved

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

Posted on 2014-04-14
2
Medium Priority
?
1,081 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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
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 use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

719 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