Home |
Search |
Today's Posts |
|
#1
|
|||
|
|||
Please how do do this in vba
Hello from Steved
I have sheet1 labeled Data, Where the below is stored I've Labeled 8 Sheets as an example 1-City, 2-Roskill and so on. Question in vba please could somebody please write me a code that would copy from the Data Sheet to the 8 individual labeled sheets. Thankyou. Depot,Name Operator,Count Annuls,Annul Value Total, Period 1-City 10925 27 29.60 200511 1-City 10943 27 54.90 200511 6-Orewa 60124 28 67.44 200511 6-Orewa 60123 17 42.10 200511 8-Panmure 10903 27 54.04 200511 8-Panmure 10915 27 45.80 200511 3-Papakura 86076 48 122.70 200511 3-Papakura 86030 30 69.54 200511 2-Roskill 20824 42 35.38 200511 2-Roskill 20751 36 83.30 200511 5-Shore 50636 40 82.60 200511 5-Shore 50600 34 104.80 200511 7-Swanson 70468 40 59.94 200511 7-Swanson 70478 39 109.50 200511 4-Wiri 40677 35 64.40 200511 4-Wiri 40662 28 58.00 200511 |
#2
|
|||
|
|||
Steved,
This assumes that all of those worksheets exist Sub Test() Dim cLastRow As Long Dim i As Long Dim iStartRow As Long Dim iLastRow As Long With Worksheets("Data Sheet") cLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row iStartRow = 1 iLastRow = 1 For i = 2 To cLastRow + 1 If .Cells(i, "A").Value < Cells(i - 1, "A").Value Then iLastRow = i - 1 .Cells(iStartRow, "A").Resize(iLastRow - iStartRow + 1).EntireRow.Copy _ Destination:=Worksheets(.Cells(i - 1, "A").Value).Range("A1") iStartRow = i iLastRow = i Else iLastRow = iLastRow + 1 End If Next i End With End Sub -- HTH RP (remove nothere from the email address if mailing direct) "Steved" wrote in message ... Hello from Steved I have sheet1 labeled Data, Where the below is stored I've Labeled 8 Sheets as an example 1-City, 2-Roskill and so on. Question in vba please could somebody please write me a code that would copy from the Data Sheet to the 8 individual labeled sheets. Thankyou. Depot,Name Operator,Count Annuls,Annul Value Total, Period 1-City 10925 27 29.60 200511 1-City 10943 27 54.90 200511 6-Orewa 60124 28 67.44 200511 6-Orewa 60123 17 42.10 200511 8-Panmure 10903 27 54.04 200511 8-Panmure 10915 27 45.80 200511 3-Papakura 86076 48 122.70 200511 3-Papakura 86030 30 69.54 200511 2-Roskill 20824 42 35.38 200511 2-Roskill 20751 36 83.30 200511 5-Shore 50636 40 82.60 200511 5-Shore 50600 34 104.80 200511 7-Swanson 70468 40 59.94 200511 7-Swanson 70478 39 109.50 200511 4-Wiri 40677 35 64.40 200511 4-Wiri 40662 28 58.00 200511 |
#3
|
|||
|
|||
Hello from Steved
Firstly thankyou very much The macro is highlighting "Else" giving me Compile error, ELSE without IF Please what is required here. Thanks very much in advance. Sub Test() Dim cLastRow As Long Dim i As Long Dim iStartRow As Long Dim iLastRow As Long With Worksheets("Data Sheet") cLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row iStartRow = 1 iLastRow = 1 For i = 2 To cLastRow + 1 If .Cells(i, "A").Value < Cells(i - 1, "A").Value Then iLastRow = i - 1 .Cells(iStartRow, "A").Resize(iLastRow - iStartRow + 1).EntireRow.Copy _ Destination:=Worksheets(.Cells(i - 1, "A").Value).Range("A1") iStartRow = i iLastRow = i Else iLastRow = iLastRow + 1 End If Next i End With End Sub -----Original Message----- Steved, This assumes that all of those worksheets exist Sub Test() Dim cLastRow As Long Dim i As Long Dim iStartRow As Long Dim iLastRow As Long With Worksheets("Data Sheet") cLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row iStartRow = 1 iLastRow = 1 For i = 2 To cLastRow + 1 If .Cells(i, "A").Value < Cells(i - 1, "A").Value Then iLastRow = i - 1 .Cells(iStartRow, "A").Resize(iLastRow - iStartRow + 1).EntireRow.Copy _ Destination:=Worksheets(.Cells(i - 1, "A").Value).Range("A1") iStartRow = i iLastRow = i Else iLastRow = iLastRow + 1 End If Next i End With End Sub -- HTH RP (remove nothere from the email address if mailing direct) "Steved" wrote in message ... Hello from Steved I have sheet1 labeled Data, Where the below is stored I've Labeled 8 Sheets as an example 1-City, 2-Roskill and so on. Question in vba please could somebody please write me a code that would copy from the Data Sheet to the 8 individual labeled sheets. Thankyou. Depot,Name Operator,Count Annuls,Annul Value Total, Period 1-City 10925 27 29.60 200511 1-City 10943 27 54.90 200511 6-Orewa 60124 28 67.44 200511 6-Orewa 60123 17 42.10 200511 8-Panmure 10903 27 54.04 200511 8-Panmure 10915 27 45.80 200511 3-Papakura 86076 48 122.70 200511 3-Papakura 86030 30 69.54 200511 2-Roskill 20824 42 35.38 200511 2-Roskill 20751 36 83.30 200511 5-Shore 50636 40 82.60 200511 5-Shore 50600 34 104.80 200511 7-Swanson 70468 40 59.94 200511 7-Swanson 70478 39 109.50 200511 4-Wiri 40677 35 64.40 200511 4-Wiri 40662 28 58.00 200511 . |
#4
|
|||
|
|||
Probably wrap-around in the NG Steved.
Try this split version Sub Test() Dim cLastRow As Long Dim i As Long Dim iStartRow As Long Dim iLastRow As Long With Worksheets("Data Sheet") cLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row iStartRow = 1 iLastRow = 1 For i = 2 To cLastRow + 1 If .Cells(i, "A").Value < Cells(i - _ 1, "A").Value Then iLastRow = i - 1 .Cells(iStartRow, "A").Resize(iLastRow - _ iStartRow + 1).EntireRow.Copy _ Destination:=Worksheets(.Cells(i - _ 1, "A").Value).Range("A1") iStartRow = i iLastRow = i Else iLastRow = iLastRow + 1 End If Next i End With End Sub -- HTH RP (remove nothere from the email address if mailing direct) "Steved" wrote in message ... Hello from Steved Firstly thankyou very much The macro is highlighting "Else" giving me Compile error, ELSE without IF Please what is required here. Thanks very much in advance. Sub Test() Dim cLastRow As Long Dim i As Long Dim iStartRow As Long Dim iLastRow As Long With Worksheets("Data Sheet") cLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row iStartRow = 1 iLastRow = 1 For i = 2 To cLastRow + 1 If .Cells(i, "A").Value < Cells(i - 1, "A").Value Then iLastRow = i - 1 .Cells(iStartRow, "A").Resize(iLastRow - iStartRow + 1).EntireRow.Copy _ Destination:=Worksheets(.Cells(i - 1, "A").Value).Range("A1") iStartRow = i iLastRow = i Else iLastRow = iLastRow + 1 End If Next i End With End Sub -----Original Message----- Steved, This assumes that all of those worksheets exist Sub Test() Dim cLastRow As Long Dim i As Long Dim iStartRow As Long Dim iLastRow As Long With Worksheets("Data Sheet") cLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row iStartRow = 1 iLastRow = 1 For i = 2 To cLastRow + 1 If .Cells(i, "A").Value < Cells(i - 1, "A").Value Then iLastRow = i - 1 .Cells(iStartRow, "A").Resize(iLastRow - iStartRow + 1).EntireRow.Copy _ Destination:=Worksheets(.Cells(i - 1, "A").Value).Range("A1") iStartRow = i iLastRow = i Else iLastRow = iLastRow + 1 End If Next i End With End Sub -- HTH RP (remove nothere from the email address if mailing direct) "Steved" wrote in message ... Hello from Steved I have sheet1 labeled Data, Where the below is stored I've Labeled 8 Sheets as an example 1-City, 2-Roskill and so on. Question in vba please could somebody please write me a code that would copy from the Data Sheet to the 8 individual labeled sheets. Thankyou. Depot,Name Operator,Count Annuls,Annul Value Total, Period 1-City 10925 27 29.60 200511 1-City 10943 27 54.90 200511 6-Orewa 60124 28 67.44 200511 6-Orewa 60123 17 42.10 200511 8-Panmure 10903 27 54.04 200511 8-Panmure 10915 27 45.80 200511 3-Papakura 86076 48 122.70 200511 3-Papakura 86030 30 69.54 200511 2-Roskill 20824 42 35.38 200511 2-Roskill 20751 36 83.30 200511 5-Shore 50636 40 82.60 200511 5-Shore 50600 34 104.80 200511 7-Swanson 70468 40 59.94 200511 7-Swanson 70478 39 109.50 200511 4-Wiri 40677 35 64.40 200511 4-Wiri 40662 28 58.00 200511 . |
#5
|
|||
|
|||
Sorry, correction
Sub Test() Dim cLastRow As Long Dim i As Long Dim iStartRow As Long Dim iLastRow As Long With Worksheets("Data Sheet") cLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row iStartRow = 1 iLastRow = 1 For i = 2 To cLastRow + 1 If .Cells(i, "A").Value < Cells(i - _ 1, "A").Value Then iLastRow = i - 1 .Cells(iStartRow, "A").Resize(iLastRow - _ iStartRow + 1).EntireRow.Copy _ Destination:=Worksheets(.Cells(i - _ 1, "A").Value).Range("A1") iStartRow = i iLastRow = i Else iLastRow = iLastRow + 1 End If Next i End With End Sub -- HTH RP (remove nothere from the email address if mailing direct) "Bob Phillips" wrote in message ... Probably wrap-around in the NG Steved. Try this split version Sub Test() Dim cLastRow As Long Dim i As Long Dim iStartRow As Long Dim iLastRow As Long With Worksheets("Data Sheet") cLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row iStartRow = 1 iLastRow = 1 For i = 2 To cLastRow + 1 If .Cells(i, "A").Value < Cells(i - _ 1, "A").Value Then iLastRow = i - 1 .Cells(iStartRow, "A").Resize(iLastRow - _ iStartRow + 1).EntireRow.Copy _ Destination:=Worksheets(.Cells(i - _ 1, "A").Value).Range("A1") iStartRow = i iLastRow = i Else iLastRow = iLastRow + 1 End If Next i End With End Sub -- HTH RP (remove nothere from the email address if mailing direct) "Steved" wrote in message ... Hello from Steved Firstly thankyou very much The macro is highlighting "Else" giving me Compile error, ELSE without IF Please what is required here. Thanks very much in advance. Sub Test() Dim cLastRow As Long Dim i As Long Dim iStartRow As Long Dim iLastRow As Long With Worksheets("Data Sheet") cLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row iStartRow = 1 iLastRow = 1 For i = 2 To cLastRow + 1 If .Cells(i, "A").Value < Cells(i - 1, "A").Value Then iLastRow = i - 1 .Cells(iStartRow, "A").Resize(iLastRow - iStartRow + 1).EntireRow.Copy _ Destination:=Worksheets(.Cells(i - 1, "A").Value).Range("A1") iStartRow = i iLastRow = i Else iLastRow = iLastRow + 1 End If Next i End With End Sub -----Original Message----- Steved, This assumes that all of those worksheets exist Sub Test() Dim cLastRow As Long Dim i As Long Dim iStartRow As Long Dim iLastRow As Long With Worksheets("Data Sheet") cLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row iStartRow = 1 iLastRow = 1 For i = 2 To cLastRow + 1 If .Cells(i, "A").Value < Cells(i - 1, "A").Value Then iLastRow = i - 1 .Cells(iStartRow, "A").Resize(iLastRow - iStartRow + 1).EntireRow.Copy _ Destination:=Worksheets(.Cells(i - 1, "A").Value).Range("A1") iStartRow = i iLastRow = i Else iLastRow = iLastRow + 1 End If Next i End With End Sub -- HTH RP (remove nothere from the email address if mailing direct) "Steved" wrote in message ... Hello from Steved I have sheet1 labeled Data, Where the below is stored I've Labeled 8 Sheets as an example 1-City, 2-Roskill and so on. Question in vba please could somebody please write me a code that would copy from the Data Sheet to the 8 individual labeled sheets. Thankyou. Depot,Name Operator,Count Annuls,Annul Value Total, Period 1-City 10925 27 29.60 200511 1-City 10943 27 54.90 200511 6-Orewa 60124 28 67.44 200511 6-Orewa 60123 17 42.10 200511 8-Panmure 10903 27 54.04 200511 8-Panmure 10915 27 45.80 200511 3-Papakura 86076 48 122.70 200511 3-Papakura 86030 30 69.54 200511 2-Roskill 20824 42 35.38 200511 2-Roskill 20751 36 83.30 200511 5-Shore 50636 40 82.60 200511 5-Shore 50600 34 104.80 200511 7-Swanson 70468 40 59.94 200511 7-Swanson 70478 39 109.50 200511 4-Wiri 40677 35 64.40 200511 4-Wiri 40662 28 58.00 200511 . |
#6
|
|||
|
|||
Hello Bob from Steved
I am getting Subscript out of Range. Thanks for your patience. -----Original Message----- Sorry, correction Sub Test() Dim cLastRow As Long Dim i As Long Dim iStartRow As Long Dim iLastRow As Long With Worksheets("Data Sheet") cLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row iStartRow = 1 iLastRow = 1 For i = 2 To cLastRow + 1 If .Cells(i, "A").Value < Cells(i - _ 1, "A").Value Then iLastRow = i - 1 .Cells(iStartRow, "A").Resize(iLastRow - _ iStartRow + 1).EntireRow.Copy _ Destination:=Worksheets(.Cells(i - _ 1, "A").Value).Range("A1") iStartRow = i iLastRow = i Else iLastRow = iLastRow + 1 End If Next i End With End Sub -- HTH RP (remove nothere from the email address if mailing direct) "Bob Phillips" wrote in message ... Probably wrap-around in the NG Steved. Try this split version Sub Test() Dim cLastRow As Long Dim i As Long Dim iStartRow As Long Dim iLastRow As Long With Worksheets("Data Sheet") cLastRow = .Cells(.Rows.Count, "A").End (xlUp).Row iStartRow = 1 iLastRow = 1 For i = 2 To cLastRow + 1 If .Cells(i, "A").Value < Cells(i - _ 1, "A").Value Then iLastRow = i - 1 .Cells(iStartRow, "A").Resize(iLastRow - _ iStartRow + 1).EntireRow.Copy _ Destination:=Worksheets(.Cells(i - _ 1, "A").Value).Range("A1") iStartRow = i iLastRow = i Else iLastRow = iLastRow + 1 End If Next i End With End Sub -- HTH RP (remove nothere from the email address if mailing direct) "Steved" wrote in message ... Hello from Steved Firstly thankyou very much The macro is highlighting "Else" giving me Compile error, ELSE without IF Please what is required here. Thanks very much in advance. Sub Test() Dim cLastRow As Long Dim i As Long Dim iStartRow As Long Dim iLastRow As Long With Worksheets("Data Sheet") cLastRow = .Cells(.Rows.Count, "A").End (xlUp).Row iStartRow = 1 iLastRow = 1 For i = 2 To cLastRow + 1 If .Cells(i, "A").Value < Cells(i - 1, "A").Value Then iLastRow = i - 1 .Cells(iStartRow, "A").Resize (iLastRow - iStartRow + 1).EntireRow.Copy _ Destination:=Worksheets(.Cells(i - 1, "A").Value).Range("A1") iStartRow = i iLastRow = i Else iLastRow = iLastRow + 1 End If Next i End With End Sub -----Original Message----- Steved, This assumes that all of those worksheets exist Sub Test() Dim cLastRow As Long Dim i As Long Dim iStartRow As Long Dim iLastRow As Long With Worksheets("Data Sheet") cLastRow = .Cells(.Rows.Count, "A").End (xlUp).Row iStartRow = 1 iLastRow = 1 For i = 2 To cLastRow + 1 If .Cells(i, "A").Value < Cells(i - 1, "A").Value Then iLastRow = i - 1 .Cells(iStartRow, "A").Resize (iLastRow - iStartRow + 1).EntireRow.Copy _ Destination:=Worksheets(.Cells (i - 1, "A").Value).Range("A1") iStartRow = i iLastRow = i Else iLastRow = iLastRow + 1 End If Next i End With End Sub -- HTH RP (remove nothere from the email address if mailing direct) "Steved" wrote in message ... Hello from Steved I have sheet1 labeled Data, Where the below is stored I've Labeled 8 Sheets as an example 1-City, 2- Roskill and so on. Question in vba please could somebody please write me a code that would copy from the Data Sheet to the 8 individual labeled sheets. Thankyou. Depot,Name Operator,Count Annuls,Annul Value Total, Period 1-City 10925 27 29.60 200511 1-City 10943 27 54.90 200511 6-Orewa 60124 28 67.44 200511 6-Orewa 60123 17 42.10 200511 8-Panmure 10903 27 54.04 200511 8-Panmure 10915 27 45.80 200511 3-Papakura 86076 48 122.70 200511 3-Papakura 86030 30 69.54 200511 2-Roskill 20824 42 35.38 200511 2-Roskill 20751 36 83.30 200511 5-Shore 50636 40 82.60 200511 5-Shore 50600 34 104.80 200511 7-Swanson 70468 40 59.94 200511 7-Swanson 70478 39 109.50 200511 4-Wiri 40677 35 64.40 200511 4-Wiri 40662 28 58.00 200511 . . |
#7
|
|||
|
|||
Hello Bob from Steved
Bob firstly thankyou I am getting the same error ELSE Compile error: Else without IF Thankyou. -----Original Message----- Probably wrap-around in the NG Steved. Try this split version Sub Test() Dim cLastRow As Long Dim i As Long Dim iStartRow As Long Dim iLastRow As Long With Worksheets("Data Sheet") cLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row iStartRow = 1 iLastRow = 1 For i = 2 To cLastRow + 1 If .Cells(i, "A").Value < Cells(i - _ 1, "A").Value Then iLastRow = i - 1 .Cells(iStartRow, "A").Resize(iLastRow - _ iStartRow + 1).EntireRow.Copy _ Destination:=Worksheets(.Cells(i - _ 1, "A").Value).Range("A1") iStartRow = i iLastRow = i Else iLastRow = iLastRow + 1 End If Next i End With End Sub -- HTH RP (remove nothere from the email address if mailing direct) "Steved" wrote in message ... Hello from Steved Firstly thankyou very much The macro is highlighting "Else" giving me Compile error, ELSE without IF Please what is required here. Thanks very much in advance. Sub Test() Dim cLastRow As Long Dim i As Long Dim iStartRow As Long Dim iLastRow As Long With Worksheets("Data Sheet") cLastRow = .Cells(.Rows.Count, "A").End (xlUp).Row iStartRow = 1 iLastRow = 1 For i = 2 To cLastRow + 1 If .Cells(i, "A").Value < Cells(i - 1, "A").Value Then iLastRow = i - 1 .Cells(iStartRow, "A").Resize(iLastRow - iStartRow + 1).EntireRow.Copy _ Destination:=Worksheets(.Cells(i - 1, "A").Value).Range("A1") iStartRow = i iLastRow = i Else iLastRow = iLastRow + 1 End If Next i End With End Sub -----Original Message----- Steved, This assumes that all of those worksheets exist Sub Test() Dim cLastRow As Long Dim i As Long Dim iStartRow As Long Dim iLastRow As Long With Worksheets("Data Sheet") cLastRow = .Cells(.Rows.Count, "A").End (xlUp).Row iStartRow = 1 iLastRow = 1 For i = 2 To cLastRow + 1 If .Cells(i, "A").Value < Cells(i - 1, "A").Value Then iLastRow = i - 1 .Cells(iStartRow, "A").Resize (iLastRow - iStartRow + 1).EntireRow.Copy _ Destination:=Worksheets(.Cells(i - 1, "A").Value).Range("A1") iStartRow = i iLastRow = i Else iLastRow = iLastRow + 1 End If Next i End With End Sub -- HTH RP (remove nothere from the email address if mailing direct) "Steved" wrote in message ... Hello from Steved I have sheet1 labeled Data, Where the below is stored I've Labeled 8 Sheets as an example 1-City, 2-Roskill and so on. Question in vba please could somebody please write me a code that would copy from the Data Sheet to the 8 individual labeled sheets. Thankyou. Depot,Name Operator,Count Annuls,Annul Value Total, Period 1-City 10925 27 29.60 200511 1-City 10943 27 54.90 200511 6-Orewa 60124 28 67.44 200511 6-Orewa 60123 17 42.10 200511 8-Panmure 10903 27 54.04 200511 8-Panmure 10915 27 45.80 200511 3-Papakura 86076 48 122.70 200511 3-Papakura 86030 30 69.54 200511 2-Roskill 20824 42 35.38 200511 2-Roskill 20751 36 83.30 200511 5-Shore 50636 40 82.60 200511 5-Shore 50600 34 104.80 200511 7-Swanson 70468 40 59.94 200511 7-Swanson 70478 39 109.50 200511 4-Wiri 40677 35 64.40 200511 4-Wiri 40662 28 58.00 200511 . . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|