willow1985
Well-known Member
- Joined
- Jul 24, 2019
- Messages
- 915
- Office Version
- 365
- Platform
- Windows
I need help with writing a macro that can copy a set amount of rows (say 15 rows) from a table of data and paste the data into another sheet (forms) at set locations one after another until there is no more data to copy in the table.
I do not know what the max amount of rows/data that will be in the table or how many forms will be required, but I do know the form will repeat every 17 rows. See below example.
I hope someone can help me with this. Loop codes are not my strong suit.
Thank you!
I do not know what the max amount of rows/data that will be in the table or how many forms will be required, but I do know the form will repeat every 17 rows. See below example.
I hope someone can help me with this. Loop codes are not my strong suit.
Thank you!
Book1 | |||||||||
---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | |||
1 | OrderDate | Region | Rep | Item | Units | Unit Cost | Total | ||
2 | 6-Jan-21 | East | Jones | Pencil | 95 | 1.99 | 189.05 | ||
3 | 23-Jan-21 | Central | Kivell | Binder | 50 | 19.99 | 999.5 | ||
4 | 9-Feb-21 | Central | Jardine | Pencil | 36 | 4.99 | 179.64 | ||
5 | 26-Feb-21 | Central | Gill | Pen | 27 | 19.99 | 539.73 | ||
6 | 15-Mar-21 | West | Sorvino | Pencil | 56 | 2.99 | 167.44 | ||
7 | 1-Apr-21 | East | Jones | Binder | 60 | 4.99 | 299.4 | ||
8 | 18-Apr-21 | Central | Andrews | Pencil | 75 | 1.99 | 149.25 | ||
9 | 5-May-21 | Central | Jardine | Pencil | 90 | 4.99 | 449.1 | ||
10 | 22-May-21 | West | Thompson | Pencil | 32 | 1.99 | 63.68 | ||
11 | 8-Jun-21 | East | Jones | Binder | 60 | 8.99 | 539.4 | ||
12 | 25-Jun-21 | Central | Morgan | Pencil | 90 | 4.99 | 449.1 | ||
13 | 12-Jul-21 | East | Howard | Binder | 29 | 1.99 | 57.71 | ||
14 | 29-Jul-21 | East | Parent | Binder | 81 | 19.99 | 1619.19 | ||
15 | 15-Aug-21 | East | Jones | Pencil | 35 | 4.99 | 174.65 | ||
16 | 1-Sep-21 | Central | Smith | Desk | 2 | 125 | 250 | ||
17 | 18-Sep-21 | East | Jones | Pen Set | 16 | 15.99 | 255.84 | ||
18 | 5-Oct-21 | Central | Morgan | Binder | 28 | 8.99 | 251.72 | ||
19 | 22-Oct-21 | East | Jones | Pen | 64 | 8.99 | 575.36 | ||
20 | 8-Nov-21 | East | Parent | Pen | 15 | 19.99 | 299.85 | ||
21 | 25-Nov-21 | Central | Kivell | Pen Set | 96 | 4.99 | 479.04 | ||
22 | 12-Dec-21 | Central | Smith | Pencil | 67 | 1.29 | 86.43 | ||
23 | 29-Dec-21 | East | Parent | Pen Set | 74 | 15.99 | 1183.26 | ||
24 | 15-Jan-22 | Central | Gill | Binder | 46 | 8.99 | 413.54 | ||
25 | 1-Feb-22 | Central | Smith | Binder | 87 | 15 | 1305 | ||
26 | 18-Feb-22 | East | Jones | Binder | 4 | 4.99 | 19.96 | ||
27 | 7-Mar-22 | West | Sorvino | Binder | 7 | 19.99 | 139.93 | ||
28 | 24-Mar-22 | Central | Jardine | Pen Set | 50 | 4.99 | 249.5 | ||
29 | 10-Apr-22 | Central | Andrews | Pencil | 66 | 1.99 | 131.34 | ||
30 | 27-Apr-22 | East | Howard | Pen | 96 | 4.99 | 479.04 | ||
31 | 14-May-22 | Central | Gill | Pencil | 53 | 1.29 | 68.37 | ||
32 | 31-May-22 | Central | Gill | Binder | 80 | 8.99 | 719.2 | ||
33 | 17-Jun-22 | Central | Kivell | Desk | 5 | 125 | 625 | ||
34 | 4-Jul-22 | East | Jones | Pen Set | 62 | 4.99 | 309.38 | ||
35 | 21-Jul-22 | Central | Morgan | Pen Set | 55 | 12.49 | 686.95 | ||
36 | 7-Aug-22 | Central | Kivell | Pen Set | 42 | 23.95 | 1005.9 | ||
37 | 24-Aug-22 | West | Sorvino | Desk | 3 | 275 | 825 | ||
38 | 10-Sep-22 | Central | Gill | Pencil | 7 | 1.29 | 9.03 | ||
39 | 27-Sep-22 | West | Sorvino | Pen | 76 | 1.99 | 151.24 | ||
40 | 14-Oct-22 | West | Thompson | Binder | 57 | 19.99 | 1139.43 | ||
41 | 31-Oct-22 | Central | Andrews | Pencil | 14 | 1.29 | 18.06 | ||
42 | 17-Nov-22 | Central | Jardine | Binder | 11 | 4.99 | 54.89 | ||
43 | 4-Dec-22 | Central | Jardine | Binder | 94 | 19.99 | 1879.06 | ||
44 | 21-Dec-22 | Central | Andrews | Binder | 28 | 4.99 | 139.72 | ||
Data |
Book1 | |||||||||
---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | |||
1 | CENTRAL FORM | ||||||||
2 | OrderDate | Region | Rep | Item | Units | Unit Cost | Total | ||
3 | 23-Jan-21 | Central | Kivell | Binder | 50 | 19.99 | 999.5 | ||
4 | 9-Feb-21 | Central | Jardine | Pencil | 36 | 4.99 | 179.64 | ||
5 | 26-Feb-21 | Central | Gill | Pen | 27 | 19.99 | 539.73 | ||
6 | 18-Apr-21 | Central | Andrews | Pencil | 75 | 1.99 | 149.25 | ||
7 | 5-May-21 | Central | Jardine | Pencil | 90 | 4.99 | 449.1 | ||
8 | 25-Jun-21 | Central | Morgan | Pencil | 90 | 4.99 | 449.1 | ||
9 | 1-Sep-21 | Central | Smith | Desk | 2 | 125 | 250 | ||
10 | 5-Oct-21 | Central | Morgan | Binder | 28 | 8.99 | 251.72 | ||
11 | 25-Nov-21 | Central | Kivell | Pen Set | 96 | 4.99 | 479.04 | ||
12 | 12-Dec-21 | Central | Smith | Pencil | 67 | 1.29 | 86.43 | ||
13 | 15-Jan-22 | Central | Gill | Binder | 46 | 8.99 | 413.54 | ||
14 | 1-Feb-22 | Central | Smith | Binder | 87 | 15 | 1305 | ||
15 | 24-Mar-22 | Central | Jardine | Pen Set | 50 | 4.99 | 249.5 | ||
16 | 10-Apr-22 | Central | Andrews | Pencil | 66 | 1.99 | 131.34 | ||
17 | 14-May-22 | Central | Gill | Pencil | 53 | 1.29 | 68.37 | ||
18 | Company Name | ||||||||
19 | CENTRAL FORM | ||||||||
20 | OrderDate | Region | Rep | Item | Units | Unit Cost | Total | ||
21 | 31-May-22 | Central | Gill | Binder | 80 | 8.99 | 719.2 | ||
22 | 17-Jun-22 | Central | Kivell | Desk | 5 | 125 | 625 | ||
23 | 21-Jul-22 | Central | Morgan | Pen Set | 55 | 12.49 | 686.95 | ||
24 | 7-Aug-22 | Central | Kivell | Pen Set | 42 | 23.95 | 1005.9 | ||
25 | 10-Sep-22 | Central | Gill | Pencil | 7 | 1.29 | 9.03 | ||
26 | 31-Oct-22 | Central | Andrews | Pencil | 14 | 1.29 | 18.06 | ||
27 | 17-Nov-22 | Central | Jardine | Binder | 11 | 4.99 | 54.89 | ||
28 | 4-Dec-22 | Central | Jardine | Binder | 94 | 19.99 | 1879.06 | ||
29 | 21-Dec-22 | Central | Andrews | Binder | 28 | 4.99 | 139.72 | ||
30 | |||||||||
31 | |||||||||
32 | |||||||||
33 | |||||||||
34 | |||||||||
35 | |||||||||
36 | Company Name | ||||||||
37 | CENTRAL FORM | ||||||||
38 | OrderDate | Region | Rep | Item | Units | Unit Cost | Total | ||
39 | |||||||||
40 | |||||||||
41 | |||||||||
42 | |||||||||
43 | |||||||||
44 | |||||||||
45 | |||||||||
46 | |||||||||
47 | |||||||||
48 | |||||||||
49 | |||||||||
50 | |||||||||
51 | |||||||||
52 | |||||||||
53 | |||||||||
54 | Company Name | ||||||||
55 | CENTRAL FORM | ||||||||
56 | OrderDate | Region | Rep | Item | Units | Unit Cost | Total | ||
57 | |||||||||
58 | |||||||||
59 | |||||||||
60 | |||||||||
61 | |||||||||
62 | |||||||||
63 | |||||||||
64 | |||||||||
65 | |||||||||
66 | |||||||||
67 | |||||||||
68 | |||||||||
69 | |||||||||
70 | |||||||||
71 | |||||||||
72 | Company Name | ||||||||
Central Form |
VBA Code:
Sub Macro3()
'
' Macro3 Macro
'
'
ActiveSheet.ListObjects("Order_Data").Range.AutoFilter Field:=2, Criteria1:= _
"Central"
Range("A3:G31").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("Central Form").Select
Range("A3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Data").Select
Range("A32:G44").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Central Form").Select
Range("A21").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub