Solved

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

Posted on 2014-04-14
2
929 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
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

810 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