Solved

Split Excel Data into Multiple Excel Sheets

Posted on 2011-09-27
6
245 Views
Last Modified: 2012-05-12
I am using Excel 2007. I have Employee Data in a Excel Workbook called Employee.xls.
All the data is in a worksheet called Data. It has columns like Employee name,Dept number, Salary, Comission. All the data is sorted by Employee name.  The data contains multiple records of different employees. For example there would be 10 records of Chris Smith, 20 records of Edward Martin, 30 records of John Holt... etc.

I need to parse through the entire Data worksheet and every time there is a change in the Employee name,  I need to create a new worksheet and put the entire data of that employee in the new sheet. For example Chris Smith would have a new sheet with his data of name , Dept, salary and comission.. Simiilary Edward MArtin and John Holt would have their own worksheet tabs with their own respective information.

Could some one please suggest an Excel VBA code as to how achieve this?

Thanks
0
Comment
Question by:vsuripeddi
6 Comments
 

Author Comment

by:vsuripeddi
ID: 36714845
Please provide Excel VBA Code or macros
0
 
LVL 33

Expert Comment

by:Rob Henson
ID: 36715150
Before you start, how many employees do you have data for? Obviously more than just a few or else it wouldn't need a routine to accomplish the task.

Excel has a limit to how many sheets it can accommodate. It used to be 256 but I don't know if that has increased with newer versions.

Do you want to permanently separate the data into individual sheets or just for reporting purposes keeping the original intact?

Sounds like you could use the AutoFilter function. When you apply the filter and copy the cells, only the visible cells are copied so can be pasted into a separate sheet  as required. If the cells are not contiguous, all the Chris Smith rows for example are togther, the copied data will not include formulas, they will be converted to value. If they are contiguous the formulas will stay and will recalculate.

Do a search on EE for Filter copy routines and you will find some that have been used by other users recently.

Thanks
Rob H
0
 
LVL 5

Expert Comment

by:GirardAndrew
ID: 36715681
Hi,

I think what you want to do is this:

1- use a form to pull up the list of employees from Data worksheet and select which you want to update
2- use another form to update employee information
3- on save, populate the information to a separate sheet

This could be easily done.

Thanks,
Girard Andrew
0
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!

 
LVL 10

Expert Comment

by:ukerandi
ID: 36716101
check this

Go to Macro run the Step1 Macro
Work.xlsm
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 36717097
The following code does NOT depend on the data being sorted first.  It assumes that Sheet1 holds the original data, that there are headings in Row 1, data start in Row 2, and that Column A has the names.

It uses a Dictionary to keep track of distinct employee names; for more about that please see: http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/A_3391-Using-the-Dictionary-Class-in-VBA.html


Sub SplitThemUp()
    
    Dim dic As Object
    Dim LastR As Long
    Dim LastC As Long
    Dim arr As Variant
    Dim Counter As Long
    Dim SourceWs As Worksheet
    Dim DestWs As Worksheet
    Dim TestName As String
    
    Set dic = CreateObject("Scripting.Dictionary")
    dic.CompareMode = vbTextCompare
    
    Set SourceWs = ThisWorkbook.Worksheets("Sheet1")  'change as needed
    With SourceWs
        LastR = .Cells(.Rows.Count, "a").End(xlUp).Row
        LastC = .Cells(1, .Columns.Count).End(xlToLeft).Column
        arr = .Range("a2:a" & LastR).Value
        For Counter = 1 To UBound(arr, 1)
            TestName = arr(Counter, 1)
            If Not dic.Exists(TestName) Then
                dic.Add TestName, TestName
                .[a1].AutoFilter
                .[a1].AutoFilter , Field:=1, Criteria1:=TestName, Operator:=xlAnd
                .Parent.Worksheets.Add After:=.Parent.Worksheets(.Parent.Worksheets.Count)
                Set DestWs = .Parent.Worksheets(.Parent.Worksheets.Count)
                DestWs.[a1].Resize(1, LastC) = .[a1].Resize(1, LastC).Value
                DestWs.Name = TestName
                .Range("a2", .Cells(LastR, LastC)).SpecialCells(xlCellTypeVisible).Copy DestWs.[a2]
                DestWs.Columns.AutoFit
                .[a1].AutoFilter
            End If
        Next
    End With
    
    Set dic = Nothing
    
    MsgBox "Done"
    
End Sub

Open in new window

0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 36717117
ukerandi,

As a courtesy to you fellow Members, please always post the code you used in your comment.  By not posting the code you:

1) Force anyone wanting to see your solution to download a file and

2) Make your suggestion unsearchable for future users (and believe it or not, the vast majority of EE Members search the question database rather than ask new questions)

Thanks!

Patrick
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
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…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

685 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