Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

Split Excel Data into Multiple Excel Sheets

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
vsuripeddi
Asked:
vsuripeddi
1 Solution
 
vsuripeddiAuthor Commented:
Please provide Excel VBA Code or macros
0
 
Rob HensonIT & Database AssistantCommented:
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
 
GirardAndrewCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
ukerandiCommented:
check this

Go to Macro run the Step1 Macro
Work.xlsm
0
 
Patrick MatthewsCommented:
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
 
Patrick MatthewsCommented:
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

Industry Leaders: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now