Solved

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

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

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now