Solved

Split Excel Data into Multiple Excel Sheets

Posted on 2011-09-27
6
239 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 31

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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 tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

746 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

12 Experts available now in Live!

Get 1:1 Help Now