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
Solved

Split Excel Data into Multiple Excel Sheets

Posted on 2011-09-27
6
244 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
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 Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

856 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