willyboy58
Technical User
In a previous post, I did not do a very good job of explaining my situation or including good data. Below is some data on a worksheet (“propnova”) that needs to be filtered. This is a very abbreviated table of info. My actual table has over 200 records to filter.
Branch Fund Number Name
1 1 1500 LuLu
1 1 1510 Pheobe
1 1 1520 John
2 1 1600 Rita
2 1 1620 Connie
2 1 1650 Paul
3 1 1000 Bob
3 1 1111 Steve
3 1 1200 Dennis
3 4 2000 Jason
3 4 2222 Mark
3 4 2333 Curtis
From the above table, I need four new worksheets with the names: Branch 1, Branch 2, Branch 3 and NOVA. Worksheets for Branch 1, 2 and 3 will have employees with the Fund code “1” and Worksheet NOVA will have employees with the Fund code “4”. Please note that branch 3 from the table has employees with both Fund 1 and Fund 4. The Fund 4 people are the NOVA people that need their own worksheet too. The following code separates the 3 branches, but not the NOVA people to their own worksheet. Please note that the following code is used with other procedures to manipulate a lot of data.
Sub SeparateBranchesAndNova()
Application.ScreenUpdating = False
Dim curVal As Long, lRow As Long, origSht As Worksheet
Windows("propnova.xls"
.Activate
Range("A1"
.Select
Selection.EntireRow.Insert
Activecell.FormulaR1C1 = "Branch"
Range("B1"
.Select
Activecell.FormulaR1C1 = "Fund"
Range("C1"
.Select
Activecell.FormulaR1C1 = "Number"
Range("D1"
.Select
Activecell.FormulaR1C1 = "Name"
Range("E1"
.Select
Activecell.FormulaR1C1 = "Date"
Range("F1"
.Select
Activecell.FormulaR1C1 = "Job"
Range("G1"
.Select
Activecell.FormulaR1C1 = "Hours"
Set origSht = ActiveSheet
lRow = Range("A65536"
.End(xlUp).Row
For I = 2 To lRow 'assumes you put headers in and data starts at row 2
With origSht
If .Range("A" & I).Value <> .Range("A" & I - 1).Value Then
curVal = .Range("A" & I).Value
.Range("A1:F" & lRow).AutoFilter Field:=1, Criteria1:=curVal
.Range("A1:F" & lRow).Copy
Worksheets.Add
ActiveSheet.Name = "Branch " & curVal
Range("A1"
.Select
Selection.PasteSpecial
Range("A1"
.Select
Selection.EntireColumn.Delete ‘removes the fund number col
Columns("A:F"
.EntireColumn.AutoFit
Range("A1"
.Select
Else
End If
End With
Next I
Application.ScreenUpdating = True
End Sub
How do I get the NOVA people separated from the Branch 3 people and end up with the 4 worksheets: Branch 1, Branch 2, Branch 3 and NOVA?
As always, TIA.
Bill
Branch Fund Number Name
1 1 1500 LuLu
1 1 1510 Pheobe
1 1 1520 John
2 1 1600 Rita
2 1 1620 Connie
2 1 1650 Paul
3 1 1000 Bob
3 1 1111 Steve
3 1 1200 Dennis
3 4 2000 Jason
3 4 2222 Mark
3 4 2333 Curtis
From the above table, I need four new worksheets with the names: Branch 1, Branch 2, Branch 3 and NOVA. Worksheets for Branch 1, 2 and 3 will have employees with the Fund code “1” and Worksheet NOVA will have employees with the Fund code “4”. Please note that branch 3 from the table has employees with both Fund 1 and Fund 4. The Fund 4 people are the NOVA people that need their own worksheet too. The following code separates the 3 branches, but not the NOVA people to their own worksheet. Please note that the following code is used with other procedures to manipulate a lot of data.
Sub SeparateBranchesAndNova()
Application.ScreenUpdating = False
Dim curVal As Long, lRow As Long, origSht As Worksheet
Windows("propnova.xls"
Range("A1"
Selection.EntireRow.Insert
Activecell.FormulaR1C1 = "Branch"
Range("B1"
Activecell.FormulaR1C1 = "Fund"
Range("C1"
Activecell.FormulaR1C1 = "Number"
Range("D1"
Activecell.FormulaR1C1 = "Name"
Range("E1"
Activecell.FormulaR1C1 = "Date"
Range("F1"
Activecell.FormulaR1C1 = "Job"
Range("G1"
Activecell.FormulaR1C1 = "Hours"
Set origSht = ActiveSheet
lRow = Range("A65536"
For I = 2 To lRow 'assumes you put headers in and data starts at row 2
With origSht
If .Range("A" & I).Value <> .Range("A" & I - 1).Value Then
curVal = .Range("A" & I).Value
.Range("A1:F" & lRow).AutoFilter Field:=1, Criteria1:=curVal
.Range("A1:F" & lRow).Copy
Worksheets.Add
ActiveSheet.Name = "Branch " & curVal
Range("A1"
Selection.PasteSpecial
Range("A1"
Selection.EntireColumn.Delete ‘removes the fund number col
Columns("A:F"
Range("A1"
Else
End If
End With
Next I
Application.ScreenUpdating = True
End Sub
How do I get the NOVA people separated from the Branch 3 people and end up with the 4 worksheets: Branch 1, Branch 2, Branch 3 and NOVA?
As always, TIA.
Bill