Solved

MS Excel dividing rows by a sort column

Posted on 2014-02-04
2
253 Views
Last Modified: 2014-02-25
I have an Excel spreadsheet with 15,000+ rows with 15 columns and it is sorted by BillToMfgName, MfgName, StoreNbr, Category, and ItemId.  Is there a way (macro or some other) to automate the seperation of all rows for one manufacturer by the BillToMfgName column and put that information into a new spreadsheet?  And do this for each BillToMfgName in some type of automated way?

Thanks in advance for the help.

John
0
Comment
Question by:j_heck
[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
2 Comments
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 39834272
Here is a macro that uses Advanced Filter to capture a list of unique BillToMfgName, then uses AutoFilter to filter your data for each manufacturer in turn. The filtered data is copied to a new worksheet named after the manufacturer.

As written, the macro runs on the active worksheet, and assumes that your data are surrounded by empty rows and columns.
Sub BillToMfgToWorksheets()
Dim cel As Range, rg As Range, rgFilt As Range, rgUniques As Range
Dim iCol As Long
Dim v As Variant, vUniques As Variant
Dim ws As Worksheet
Application.ScreenUpdating = False
Set cel = ActiveCell
Set rg = ActiveSheet.Range("A1").CurrentRegion  'All the raw data
v = Application.Match("BillToMfgName", rg.Rows(1), 0)
If IsError(v) Then Exit Sub

iCol = v
Set rgUniques = rg.Cells(1, 1).Offset(0, rg.Columns.Count + 2)
Set rgFilt = rg.Columns(iCol)
rgFilt.AdvancedFilter Action:=xlFilterCopy, CopyToRange:=rgUniques, Unique:=True
Set rgUniques = rgUniques.Resize(rgUniques.CurrentRegion.Rows.Count, 1)
vUniques = rgUniques.Offset(1, 0).Resize(rgUniques.Rows.Count - 1).Value
rgUniques.ClearContents
If rgUniques.Rows.Count = 1 Then Exit Sub

For Each v In vUniques
    rg.AutoFilter
    rg.AutoFilter Field:=iCol, Criteria1:=v
    Set ws = Worksheets.Add(after:=Worksheets(Worksheets.Count))
    ws.Name = v
    rg.Copy ws.Range("A1")
Next
rg.AutoFilter
Application.Goto cel
End Sub

Open in new window

0
 
LVL 81

Expert Comment

by:byundt
ID: 39834282
Here is a sample workbook containing the macro. Push the button to see it in action.

The macro is installed on a regular module sheet.

If you want to test the macro with your data, just paste it over my test data.
FilterToNewWorksheetsQ28356225.xlsm
0

Featured Post

Technology Partners: 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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
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.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

734 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