Solved

Split Excel Data into Multiple Excel Sheets

Posted on 2011-09-27
6
241 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 32

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
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.

 
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

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
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…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

863 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

22 Experts available now in Live!

Get 1:1 Help Now