willyboy58
Technical User
I am trying to separate the following type of information in a spreadsheet. The spreadsheet does not have the headings, which is OK. Below is a tiny subset of the real information. There are over 2000 records in the main file.
Branch EmployeeID Name WorkDate Hours
1 1340 John 05-01-2003 6.0
1 1290 Susie 05-01-2003 6.0
1 1267 Dennis 05-03-2003 7.0
2 1002 Bob 05-01-2003 6.0
2 1222 Steve 05-01-2003 6.0
3 2064 Tom 05-01-2003 8.0
3 1005 Carl 05-02-2003 6.0
3 1111 Kenny 05-01-2003 6.0
I am wanting to select each branch and copy all of it’s people with their work dates and hours to their own worksheet. I will then have four sheets, the one above and one for each branch. I can’t seem to figure out how to start at A1 (which will always start with branch 1) and go to the last record for branch 1 (above would be for Dennis). After this info is copied, go back and start at branch 2 and copy all of branch 2’s people and info to their own worksheet, then do the same for branch 3. There is no way of knowing how many rows of data will be in each branch. Below is what I have so far. It is not working. Any help will be greatly appreciated. TIA. Bill
Sub SeparateBranches3()
Dim FirstCell, NextCell, Lastcell As Range
Dim SourceRange, CopyRows, TargetRange As Range
Dim NumberofRows As Integer
'start at A1
Range("A1"
.Select
FirstCell = ActiveCell.Value
NextCell = ActiveCell.Offset(1, 0).Value
Do Until NextCell <> FirstCell
With ActiveCell
If NextCell > FirstCell Then
SourceRange = ActiveCell.Offset(-1, 0).Range(FirstCell, NextCell)
CopyRows = SourceRange.Rows.Copy
'create new sheet for info above
Worksheet.Add
'paste info from above
Range("A1"
.Select
Selection.PasteSpecial
MsgBox "should be at new sheet"
End If
End With
End
Loop
End Sub
Branch EmployeeID Name WorkDate Hours
1 1340 John 05-01-2003 6.0
1 1290 Susie 05-01-2003 6.0
1 1267 Dennis 05-03-2003 7.0
2 1002 Bob 05-01-2003 6.0
2 1222 Steve 05-01-2003 6.0
3 2064 Tom 05-01-2003 8.0
3 1005 Carl 05-02-2003 6.0
3 1111 Kenny 05-01-2003 6.0
I am wanting to select each branch and copy all of it’s people with their work dates and hours to their own worksheet. I will then have four sheets, the one above and one for each branch. I can’t seem to figure out how to start at A1 (which will always start with branch 1) and go to the last record for branch 1 (above would be for Dennis). After this info is copied, go back and start at branch 2 and copy all of branch 2’s people and info to their own worksheet, then do the same for branch 3. There is no way of knowing how many rows of data will be in each branch. Below is what I have so far. It is not working. Any help will be greatly appreciated. TIA. Bill
Sub SeparateBranches3()
Dim FirstCell, NextCell, Lastcell As Range
Dim SourceRange, CopyRows, TargetRange As Range
Dim NumberofRows As Integer
'start at A1
Range("A1"
FirstCell = ActiveCell.Value
NextCell = ActiveCell.Offset(1, 0).Value
Do Until NextCell <> FirstCell
With ActiveCell
If NextCell > FirstCell Then
SourceRange = ActiveCell.Offset(-1, 0).Range(FirstCell, NextCell)
CopyRows = SourceRange.Rows.Copy
'create new sheet for info above
Worksheet.Add
'paste info from above
Range("A1"
Selection.PasteSpecial
MsgBox "should be at new sheet"
End If
End With
End
Loop
End Sub