View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Toppers Toppers is offline
external usenet poster
 
Posts: 4,339
Default Separate Variable Range of Data into Different Worksheets

Hi,

Try this:

Sub GetManagerLists()

Dim ws1 As Worksheet, ws2 As Worksheet
Dim lastrow As Long, r As Long, n As Long
Dim manager As String

Set ws1 = Worksheets("sheet1")

ws1.Activate
With ws1
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
Set myRange = .Range("c2:c" & lastrow)
r = 2
Do While r < lastrow
manager = .Cells(r, "C")
Sheets.Add after:=Sheets(Worksheets.Count)
ActiveSheet.Name = manager
Set ws2 = Worksheets(manager)
n = Application.CountIf(myRange, manager)
.Cells(r, 1).Resize(n, 2).Copy ws2.Cells(2, 1)
r = r + n
Loop
End With
End Sub


HTH
"equity7252" wrote:

I have a single worksheet with example data as shown:

A1 B1 C1
Name Job Manager

John S. Super Bill
Sue M. Analyst Bill
Jack V. Clerk Bill
Gary W. Sr Analyst Lisa
Bob N. Clerk Lisa
Tim B. Super Phyllis Z.
Nate M. Clerk Phyllis Z.
John Q. Clerk Phyllis Z.
Quin L. Analyst Phyllis Z.
Paul S. Analyst Phyllis Z.

Each manager has a varying number of employees.

I need to create a new worksheet for each manager (in the same
workbook) containing all the manager's employee's (and their Job). Thus
the final product will be a workbook with 4 worksheets: 1 with original
data, 3 containing each manager's employees.

How would I do this using VBA?