Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Generating a graph via Excel 3 22
consolidate from multiple folders 5 39
Hiding column macro 10 28
Export Query data to excel file 14 26
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

929 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

15 Experts available now in Live!

Get 1:1 Help Now