OK, the image in post#1 and the data you posted in Post #4 are different( no blanks in post #4)...which do you want to use ??
There is a difference in writing the code for each one...
if it copies data to one sheet, it should work for allActually it success in sheet 5 and 6 but fail in sheet 2 3 4
I can't access external images from where I am, hopefully someone else may be able to help.
The macro I provided previously should do the trick, but I don't understand this comment
if it copies data to one sheet, it should work for all
Excel 2007 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
1 | Pick No: | 6767 | Order No: | 12 | Customer Name: | abc | Store Name: | acb | ||
2 | Product Code | Picking Qty | no. | StorCond | InvType | StorCond | Locaion | Qty | ||
3 | product code 1 | product name 1 | 1 | Ambient | Normal | 8X1 | 404-HLC | 4 | ||
4 | product code 2 | product name 2 | 2 | Ambient | Normal | 30X1 | 512-HLC | 58 | ||
5 | product code 3 | product name 3 | 3 | Ambient | Normal | 24X1 | 512-HLC | 52 | ||
6 | product code 4 | product name 4 | 4 | Ambient | Normal | 24X1 | 5A01-02-040 | 8 | ||
7 | product code 5 | product name 5 | 5 | Ambient | Normal | 24X1 | 5A01-03-070 | 2 | ||
8 | product code 6 | product name 6 | 6 | Ambient | Normal | 12X10 | 5A02-05-020 | 10 | ||
9 | product code 7 | product name 7 | 7 | Ambient | Normal | 2X40 | 5A03-01-031 | 20 | ||
10 | product code 8 | product name 8 | 8 | Ambient | Normal | 12X1 | 5F02-01-032 | 3 | ||
11 | product code 9 | product name 9 | 9 | Ambient | Normal | 12X1 | 5F02-01-062 | 50 | ||
12 | 0 | 207 | ||||||||
13 | Pick No: | 4545 | Order No: | 23 | Customer Name: | abc | Store Name: | acb | ||
14 | Product Code | Picking Qty | no. | StorCond | InvType | StorCond | Locaion | Qty | ||
15 | product code 1 | product name 1 | 1 | Ambient | Normal | 8X1 | 404-HLC | 4 | ||
16 | product code 2 | product name 2 | 2 | Ambient | Normal | 30X1 | 512-HLC | 58 | ||
17 | product code 3 | product name 3 | 3 | Ambient | Normal | 24X1 | 512-HLC | 52 | ||
18 | 0 | 114 | ||||||||
19 | Pick No: | 2442 | Order No: | 1123 | Customer Name: | abc | Store Name: | acb | ||
20 | Product Code | Picking Qty | no. | StorCond | InvType | StorCond | Locaion | Qty | ||
21 | product code 1 | product name 1 | 1 | Ambient | Normal | 8X1 | 404-HLC | 4 | ||
22 | product code 2 | product name 2 | 2 | Ambient | Normal | 30X1 | 512-HLC | 58 | ||
23 | product code 3 | product name 3 | 3 | Ambient | Normal | 24X1 | 512-HLC | 52 | ||
24 | product code 4 | product name 4 | 4 | Ambient | Normal | 24X1 | 5A01-02-040 | 8 | ||
25 | product code 5 | product name 5 | 5 | Ambient | Normal | 24X1 | 5A01-03-070 | 2 | ||
26 | product code 6 | product name 6 | 6 | Ambient | Normal | 12X10 | 5A02-05-020 | 10 | ||
27 | 0 | 134 | ||||||||
28 | Pick No: | 55555 | Order No: | 233 | Customer Name: | abc | Store Name: | acb | ||
29 | Product Code | Picking Qty | no. | StorCond | InvType | StorCond | Locaion | Qty | ||
30 | product code 1 | product name 1 | 1 | Ambient | Normal | 8X1 | 404-HLC | 4 | ||
31 | product code 2 | product name 2 | 2 | Ambient | Normal | 30X1 | 512-HLC | 58 | ||
32 | 0 | 62 | ||||||||
33 | ||||||||||
Sheet1 |
Excel 2007 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
1 | Product Code | Picking Qty | no. | StorCond | InvType | StorCond | Locaion | Qty | ||
2 | product code 1 | product name 1 | 1 | Ambient | Normal | 8X1 | 404-HLC | 4 | ||
3 | product code 1 | product name 1 | 1 | Ambient | Normal | 8X1 | 404-HLC | 4 | ||
4 | product code 1 | product name 1 | 1 | Ambient | Normal | 8X1 | 404-HLC | 4 | ||
5 | product code 1 | product name 1 | 1 | Ambient | Normal | 8X1 | 404-HLC | 4 | ||
6 | ||||||||||
1 |
Excel 2007 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
1 | Product Code | Picking Qty | no. | StorCond | InvType | StorCond | Locaion | Qty | ||
2 | product code 9 | product name 9 | 9 | Ambient | Normal | 12X1 | 5F02-01-062 | 50 | ||
3 | ||||||||||
9 |
Sub DistributeRows()
' hiker95, 06/22/2014, ME785238
Dim w1 As Worksheet, ws As Worksheet, w As String
Dim Area As Range, r As Long, sr As Long, er As Long, nr As Long
Application.ScreenUpdating = False
Set w1 = Sheets("Sheet1")
For Each Area In w1.Range("B1", w1.Range("B" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Areas
With Area
sr = .Row
er = sr + .Rows.Count - 1
For r = sr + 2 To er Step 1
w = w1.Cells(r, 3).Value
If Not WorksheetExists(w) Then
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = w
End If
Set ws = Sheets(w)
ws.Cells(1, 1).Resize(, 8).Value = Array("Product Code", "Picking Qty", "no.", "StorCond", "InvType", "StorCond", "Locaion", "Qty")
nr = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row + 1
ws.Cells(nr, 1).Resize(, 8).Value = w1.Cells(r, 1).Resize(, 8).Value
ws.Columns.AutoFit
Next r
End With
Next Area
w1.Activate
Application.ScreenUpdating = True
End Sub
Function WorksheetExists(w As String) As Boolean
On Error Resume Next
WorksheetExists = Worksheets(w).Name = w
On Error GoTo 0
End Function
miracleyy,
Sample raw data in worksheet Sheet1:
Excel 2007
A B C D E F G H 1 Pick No: 6767 Order No: 12 Customer Name: abc Store Name: acb 2 Product Code Picking Qty no. StorCond InvType StorCond Locaion Qty 3 product code 1 product name 1 1 Ambient Normal 8X1 404-HLC 4 4 product code 2 product name 2 2 Ambient Normal 30X1 512-HLC 58 5 product code 3 product name 3 3 Ambient Normal 24X1 512-HLC 52 6 product code 4 product name 4 4 Ambient Normal 24X1 5A01-02-040 8 7 product code 5 product name 5 5 Ambient Normal 24X1 5A01-03-070 2 8 product code 6 product name 6 6 Ambient Normal 12X10 5A02-05-020 10 9 product code 7 product name 7 7 Ambient Normal 2X40 5A03-01-031 20 10 product code 8 product name 8 8 Ambient Normal 12X1 5F02-01-032 3 11 product code 9 product name 9 9 Ambient Normal 12X1 5F02-01-062 50 12 0 207 13 Pick No: 4545 Order No: 23 Customer Name: abc Store Name: acb 14 Product Code Picking Qty no. StorCond InvType StorCond Locaion Qty 15 product code 1 product name 1 1 Ambient Normal 8X1 404-HLC 4 16 product code 2 product name 2 2 Ambient Normal 30X1 512-HLC 58 17 product code 3 product name 3 3 Ambient Normal 24X1 512-HLC 52 18 0 114 19 Pick No: 2442 Order No: 1123 Customer Name: abc Store Name: acb 20 Product Code Picking Qty no. StorCond InvType StorCond Locaion Qty 21 product code 1 product name 1 1 Ambient Normal 8X1 404-HLC 4 22 product code 2 product name 2 2 Ambient Normal 30X1 512-HLC 58 23 product code 3 product name 3 3 Ambient Normal 24X1 512-HLC 52 24 product code 4 product name 4 4 Ambient Normal 24X1 5A01-02-040 8 25 product code 5 product name 5 5 Ambient Normal 24X1 5A01-03-070 2 26 product code 6 product name 6 6 Ambient Normal 12X10 5A02-05-020 10 27 0 134 28 Pick No: 55555 Order No: 233 Customer Name: abc Store Name: acb 29 Product Code Picking Qty no. StorCond InvType StorCond Locaion Qty 30 product code 1 product name 1 1 Ambient Normal 8X1 404-HLC 4 31 product code 2 product name 2 2 Ambient Normal 30X1 512-HLC 58 32 0 62 33
<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>Sheet1
After the macro in worksheets 1, and, 9 (not all sheets are shown):
Excel 2007
A B C D E F G H 1 Product Code Picking Qty no. StorCond InvType StorCond Locaion Qty 2 product code 1 product name 1 1 Ambient Normal 8X1 404-HLC 4 3 product code 1 product name 1 1 Ambient Normal 8X1 404-HLC 4 4 product code 1 product name 1 1 Ambient Normal 8X1 404-HLC 4 5 product code 1 product name 1 1 Ambient Normal 8X1 404-HLC 4 6
<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>1
Excel 2007
A B C D E F G H 1 Product Code Picking Qty no. StorCond InvType StorCond Locaion Qty 2 product code 9 product name 9 9 Ambient Normal 12X1 5F02-01-062 50 3
<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>9
Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).
Code:Sub DistributeRows() ' hiker95, 06/22/2014, ME785238 Dim w1 As Worksheet, ws As Worksheet, w As String Dim Area As Range, r As Long, sr As Long, er As Long, nr As Long Application.ScreenUpdating = False Set w1 = Sheets("Sheet1") For Each Area In w1.Range("B1", w1.Range("B" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Areas With Area sr = .Row er = sr + .Rows.Count - 1 For r = sr + 2 To er Step 1 w = w1.Cells(r, 3).Value If Not WorksheetExists(w) Then Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = w End If Set ws = Sheets(w) ws.Cells(1, 1).Resize(, 8).Value = Array("Product Code", "Picking Qty", "no.", "StorCond", "InvType", "StorCond", "Locaion", "Qty") nr = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row + 1 ws.Cells(nr, 1).Resize(, 8).Value = w1.Cells(r, 1).Resize(, 8).Value ws.Columns.AutoFit Next r End With Next Area w1.Activate Application.ScreenUpdating = True End Sub Function WorksheetExists(w As String) As Boolean On Error Resume Next WorksheetExists = Worksheets(w).Name = w On Error GoTo 0 End Function
Before you use the macro and function with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm
Then run the DistributeRows macro.