Button to split work and place it in separate sheets

Shamas

Board Regular
Joined
Aug 24, 2006
Messages
64
Hi, there are occasions when I am allocated some work. I would like to be able to paste that work into my spreadsheet from cell A4 onwards and then enter how many staff I have available in B2. A quick button press would then hopefully split the work by the number of staff by making individual sheets for me retaining the header row (row 4) on each new sheet created. Can you help please?

Excel Workbook
ABCDEFG
1
2Number of staff3
3
4DateTimeNameCodeCommentsNumber
501/09/201119:00:00JoeA12121Order booked07777 111222
602/09/201120:00:00JoeA12122Order booked07778 111222
703/09/201121:00:00JoeA12123Order booked07778 111222
804/09/201122:00:00JoeA12124Order booked07778 111222
905/09/201123:00:00JoeA12125Order booked07778 111222
1006/09/201100:00:00JoeA12126Order booked07778 111222
1107/09/201101:00:00JoeA12127Order booked07778 111222
1208/09/201102:00:00JoeA12128Order booked07778 111222
1309/09/201103:00:00JoeA12129Order booked07778 111222
1410/09/201104:00:00JoeA12130Order booked07778 111222
1511/09/201105:00:00JoeA12131Order booked07778 111222
16
17
RAW DATA
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try this code on a backup. Even if it isn't what you need it should get you started anyway :)
Code:
Private Sub CommandButton1_Click()
Dim lLastRow As Long
Dim dRowToCopy As Integer
lLastRow = Sheets(1).Range("A" & Rows.Count).End(xlUp).Row
dRowToCopy = Application.Ceiling((lLastRow - 4) / Sheets(1).Range("B2").Value, 1)
For i = 2 To Range("B2").Value
If i > Sheets.Count Then Sheets.Add After:=Sheets(Sheets.Count)
Sheets(1).Range("A4").Resize(, 6).Copy _
Destination:=Sheets(i).Range("A" & Rows.Count).End(xlUp)(2)
Sheets(1).Range("A" & 5 + dRowToCopy).Resize(dRowToCopy, 6).Copy _
Destination:=Sheets(i).Range("A" & Rows.Count).End(xlUp)(2)
Sheets(1).Range("A" & 5 + dRowToCopy).Resize(dRowToCopy).EntireRow.Delete
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,812
Members
452,945
Latest member
Bib195

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top