Re Arranging Data in Excel

DEBR

New Member
Joined
Sep 9, 2009
Messages
20
The data below is downloaded from our inhouse software program. I would like to set the data into a table. The first spreadsheet is how it is downloaded. THe second spreadsheet is how I would like the table to be.
Please help to write a macro.




<TABLE style="PADDING-RIGHT: 2pt; PADDING-LEFT: 2pt; FONT-SIZE: 10pt; FONT-FAMILY: Arial,Arial; BACKGROUND-COLOR: #ffffff" cellSpacing=0 cellPadding=0 border=1><TBODY><TR style="FONT-WEIGHT: bold; FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center"><TD></TD><TD>A</TD><TD>B</TD><TD>C</TD><TD>D</TD><TD>E</TD><TD>F</TD><TD>G</TD><TD>H</TD><TD>I</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">1</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">2</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD>Invoice No 45678</TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">3</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">4</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">5</TD><TD>Order Nr 1234 DD20.08.1999 Order Type VOR </TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">6</TD><TD style="TEXT-ALIGN: right">1</TD><TD></TD><TD>PULLEY</TD><TD></TD><TD style="TEXT-ALIGN: right">8979421870</TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">7</TD><TD></TD><TD>5 EA </TD><TD>478.17 ZAR</TD><TD>1 EA</TD><TD style="TEXT-ALIGN: right">478.17</TD><TD style="TEXT-ALIGN: right">0</TD><TD style="TEXT-ALIGN: right">0</TD><TD style="TEXT-ALIGN: right">478.17</TD><TD style="TEXT-ALIGN: right">478.17</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">8</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD>Delivery no. </TD><TD style="TEXT-ALIGN: right">9.4E+09</TD><TD>Subtotal</TD><TD style="TEXT-ALIGN: right">478.17</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">9</TD><TD>Item</TD><TD></TD><TD>Description </TD><TD></TD><TD>Material</TD><TD></TD><TD></TD><TD></TD><TD>ZAR</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">10</TD><TD></TD><TD>Qty</TD><TD>Price</TD><TD>Price unit</TD><TD>Value</TD><TD>Trade Disc %</TD><TD>Trade Disc value</TD><TD>Net value</TD><TD>Total net value</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">11</TD><TD>Items total </TD><TD></TD><TD></TD><TD></TD><TD style="TEXT-ALIGN: right">478.17</TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">12</TD><TD>Output Tax </TD><TD></TD><TD></TD><TD></TD><TD style="TEXT-ALIGN: right">0.14</TD><TD style="TEXT-ALIGN: right">478.17</TD><TD></TD><TD></TD><TD style="TEXT-ALIGN: right">66.94</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">13</TD><TD>Final Amount </TD><TD></TD><TD></TD><TD></TD><TD style="TEXT-ALIGN: right">545.11</TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">14</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">15</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">16</TD><TD>Directors: D.Duck* (President & Managing Director, ABC Africa)</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">17</TD><TD>*Brazil</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">18</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">19</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">20</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD>Invoice No 12345</TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">21</TD><TD>Item</TD><TD></TD><TD>Description </TD><TD></TD><TD>Material</TD><TD></TD><TD></TD><TD></TD><TD>ZAR</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">22</TD><TD></TD><TD>Qty</TD><TD>Price</TD><TD>Price unit</TD><TD>Value</TD><TD>Trade Disc %</TD><TD>Trade Disc value</TD><TD>Net value</TD><TD>Total net value</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">23</TD><TD>Order Nr 2468 DD01.04.1999 Order Type STK </TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">24</TD><TD style="TEXT-ALIGN: right">1</TD><TD></TD><TD>BUSH;LEAF SPRING</TD><TD></TD><TD style="TEXT-ALIGN: right">8970748260</TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">25</TD><TD></TD><TD>2 EA </TD><TD>98.92 ZAR</TD><TD>1 EA</TD><TD style="TEXT-ALIGN: right">197.84</TD><TD style="TEXT-ALIGN: right">0</TD><TD style="TEXT-ALIGN: right">0</TD><TD style="TEXT-ALIGN: right">98.92</TD><TD style="TEXT-ALIGN: right">197.84</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">26</TD><TD style="TEXT-ALIGN: right">2</TD><TD></TD><TD>OUTLET ASM-WAT</TD><TD></TD><TD style="TEXT-ALIGN: right">12605785</TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">27</TD><TD></TD><TD>1 EA </TD><TD>327.38 ZAR</TD><TD>1 EA</TD><TD style="TEXT-ALIGN: right">327.38</TD><TD style="TEXT-ALIGN: right">0</TD><TD style="TEXT-ALIGN: right">0</TD><TD style="TEXT-ALIGN: right">327.38</TD><TD style="TEXT-ALIGN: right">327.38</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">28</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD>Delivery no. </TD><TD style="TEXT-ALIGN: right">9.4E+09</TD><TD>Subtotal</TD><TD style="TEXT-ALIGN: right">525.22</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">29</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">30</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">31</TD><TD>Items total </TD><TD></TD><TD></TD><TD></TD><TD style="TEXT-ALIGN: right">525.22</TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">32</TD><TD>Output Tax </TD><TD></TD><TD></TD><TD></TD><TD style="TEXT-ALIGN: right">0.14</TD><TD style="TEXT-ALIGN: right">525.22</TD><TD></TD><TD></TD><TD style="TEXT-ALIGN: right">73.53</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">33</TD><TD>Final Amount </TD><TD></TD><TD></TD><TD></TD><TD style="TEXT-ALIGN: right">598.75</TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">34</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">35</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">36</TD><TD>Directors: D.Duck* (President & Managing Director, ABC Africa)</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">37</TD><TD>*Brazil</TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD></TR></TBODY></TABLE>




<TABLE style="PADDING-RIGHT: 2pt; PADDING-LEFT: 2pt; FONT-SIZE: 10pt; FONT-FAMILY: Arial,Arial; BACKGROUND-COLOR: #ffffff" cellSpacing=0 cellPadding=0 border=1><TBODY><TR style="FONT-WEIGHT: bold; FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center"><TD>K</TD><TD>L</TD><TD>M</TD><TD>N</TD><TD>O</TD><TD>P</TD><TD>Q</TD><TD>R</TD><TD>S</TD><TD>T</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">1</TD><TD>Invoice No</TD><TD>Order Nr</TD><TD>DD</TD><TD>Order Type</TD><TD>Line</TD><TD>Description</TD><TD>Part No</TD><TD>Qty</TD><TD>Price</TD><TD>Delivery No</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">2</TD><TD style="TEXT-ALIGN: right">45678</TD><TD style="TEXT-ALIGN: right">1234</TD><TD>20.08.1999</TD><TD>VOR</TD><TD style="TEXT-ALIGN: right">1</TD><TD>PULLEY</TD><TD style="TEXT-ALIGN: right">8979421870</TD><TD style="TEXT-ALIGN: right">5</TD><TD style="TEXT-ALIGN: right">478.17</TD><TD style="TEXT-ALIGN: right">9401631530</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">3</TD><TD style="TEXT-ALIGN: right">12345</TD><TD style="TEXT-ALIGN: right">2468</TD><TD>01.04.1999</TD><TD>STK</TD><TD style="TEXT-ALIGN: right">1</TD><TD>BUSH;LEAF SPRING</TD><TD style="TEXT-ALIGN: right">8970748260</TD><TD style="TEXT-ALIGN: right">2</TD><TD style="TEXT-ALIGN: right">98.92</TD><TD style="TEXT-ALIGN: right">9401633034</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">4</TD><TD style="TEXT-ALIGN: right">12345</TD><TD style="TEXT-ALIGN: right">2468</TD><TD>01.04.2000</TD><TD>STK</TD><TD style="TEXT-ALIGN: right">2</TD><TD>OUTLET ASM-WAT</TD><TD style="TEXT-ALIGN: right">12605785</TD><TD style="TEXT-ALIGN: right">1</TD><TD style="TEXT-ALIGN: right">327.38</TD><TD style="TEXT-ALIGN: right">9401633034</TD></TR></TBODY></TABLE>
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
DEBR,


Sample data before the macro:


Excel Workbook
ABCDEFGHI
1
2Invoice No 45678
3
4
5Order Nr 1234 DD20.08.1999 Order Type VOR
61PULLEY8979421870
75 EA478.17 ZAR1 EA478.1700478.17478.17
8Delivery no.9401631530Subtotal478.17
9ItemDescriptionMaterialZAR
10QtyPricePrice unitValueTrade Disc %Trade Disc valueNet valueTotal net value
11Items total478.17
12Output Tax0.14478.1766.94
13Final Amount545.11
14
15
16Directors: D.Duck* (President & Managing Director, ABC Africa)
17*Brazil
18
19
20Invoice No 12345
21ItemDescriptionMaterialZAR
22QtyPricePrice unitValueTrade Disc %Trade Disc valueNet valueTotal net value
23Order Nr 2468 DD01.04.1999 Order Type STK
241BUSH;LEAF SPRING8970748260
252 EA98.92 ZAR1 EA197.840098.92197.84
262OUTLET ASM-WAT12605785
271 EA327.38 ZAR1 EA327.3800327.38327.38
28Delivery no.9401633034Subtotal525.22
29
30
31Items total525.22
32Output Tax0.14525.2273.53
33Final Amount598.75
34
35
36Directors: D.Duck* (President & Managing Director, ABC Africa)
37*Brazil
38
Sheet1





Excel Workbook
LMNOPQRSTU
1
2
3
4
5
6
Sheet1





After the macro:


Excel Workbook
LMNOPQRSTU
1
2Invoice NoOrder NRDDOrder TypeLineDescriptionPart NoQtyPriceDelivery No
345678123420.08.1999VOR1PULLEY89794218705478.179401631530
412345246801.04.1999STK1BUSH;LEAF SPRING8970748260298.929401633034
512345246801.04.1999STK2OUTLET ASM-WAT126057851327.389401633034
6
Sheet1





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).


1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Option Base 1
Sub ReorgData()
' hiker95, 05/10/2011
' http://www.mrexcel.com/forum/showthread.php?t=549125
Dim c As Range, firstaddress As String
Dim a As Long, aa As Long, LR As Long, i As Long, NR As Long, b As Long
Dim Iary, Sp
Application.ScreenUpdating = False
Columns("L:U").ClearContents
Range("L2:U2") = [{"Invoice No","Order NR","DD","Order Type","Line","Description","Part No","Qty","Price","Delivery No"}]
LR = Cells(Rows.Count, 1).End(xlUp).Row
i = Application.CountIf(Columns(6), "Invoice No*")
ReDim Iary(1 To i + 1)
With Columns(6)
  i = 0
  Set c = .Find("Invoice No*", LookIn:=xlValues, LookAt:=xlWhole)
  If Not c Is Nothing Then
    firstaddress = c.Address
    Do
      i = i + 1
      Iary(i) = c.Row
      Set c = .FindNext(c)
    Loop While Not c Is Nothing And c.Address <> firstaddress
  End If
End With
i = i + 1
Iary(i) = LR
For i = LBound(Iary) To UBound(Iary) - 1
  NR = Range("L" & Rows.Count).End(xlUp).Offset(1).Row
  Sp = Split(Range("F" & Iary(i)), " ")
  Range("L" & NR).Value = Sp(UBound(Sp))
  b = 0
  For a = Iary(i) To Iary(i + 1) - 1 Step 1
    If Cells(a, 1) = "" Then
      'do nothing
    ElseIf InStr(Cells(a, 1), "Order Nr") > 0 Then
      Sp = Split(Cells(a, 1), " ")
      Range("M" & NR).Value = Sp(2)
      Range("N" & NR).Value = Right(Sp(3), Len(Sp(3)) - 2)
      Range("O" & NR).Value = Sp(6)
    ElseIf IsNumeric(Cells(a, 1)) Then
      b = b + 1
      If b = 1 Then
        Range("P" & NR).Value = Cells(a, 1).Value
        Range("Q" & NR).Value = Cells(a, 3).Value
        Range("R" & NR).Value = Cells(a, 5).Value
        Sp = Split(Cells(a + 1, 2), " ")
        Range("S" & NR).Value = Sp(0)
        Sp = Split(Cells(a + 1, 3), " ")
        Range("T" & NR).Value = Sp(0)
        For aa = a To Iary(i + 1) - 1 Step 1
          If Cells(aa, 6) = "Delivery no." Then
            Range("U" & NR).Value = Cells(aa, 7).Value
            Exit For
          End If
        Next aa
      ElseIf b > 1 Then
        NR = NR + 1
        Range("L" & NR).Resize(, 4).Value = Range("L" & NR - 1).Resize(, 4).Value
        Range("P" & NR).Value = Cells(a, 1).Value
        Range("Q" & NR).Value = Cells(a, 3).Value
        Range("R" & NR).Value = Cells(a, 5).Value
        Sp = Split(Cells(a + 1, 2), " ")
        Range("S" & NR).Value = Sp(0)
        Sp = Split(Cells(a + 1, 3), " ")
        Range("T" & NR).Value = Sp(0)
        For aa = a To Iary(i + 1) - 1 Step 1
          If Cells(aa, 6) = "Delivery no." Then
            Range("U" & NR).Value = Cells(aa, 7).Value
            Exit For
          End If
        Next aa
      End If
    Else
      'do nothing
    End If
  Next a
  b = 0
Next i
Columns("L:U").AutoFit
Application.ScreenUpdating = True
End Sub


Then run the ReorgData macro.
 
Upvote 0
DEBR,


After the updated macro:


Excel Workbook
LMNOPQRSTU
1Invoice NoOrder NRDDOrder TypeLineDescriptionPart NoQtyPriceDelivery No
245678123420.08.1999VOR1PULLEY89794218705478.179401631530
312345246801.04.1999STK1BUSH;LEAF SPRING8970748260298.929401633034
412345246801.04.1999STK2OUTLET ASM-WAT126057851327.389401633034
5
Sheet1





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:
Option Explicit
Option Base 1
Sub ReorgDataV2()
' hiker95, 05/10/2011
' http://www.mrexcel.com/forum/showthread.php?t=549125
Dim c As Range, firstaddress As String
Dim a As Long, aa As Long, LR As Long, i As Long, NR As Long, b As Long
Dim Iary, Sp
Application.ScreenUpdating = False
Columns("L:U").ClearContents
Range("L1:U1") = [{"Invoice No","Order NR","DD","Order Type","Line","Description","Part No","Qty","Price","Delivery No"}]
LR = Cells(Rows.Count, 1).End(xlUp).Row
i = Application.CountIf(Columns(6), "Invoice No*")
ReDim Iary(1 To i + 1)
With Columns(6)
  i = 0
  Set c = .Find("Invoice No*", LookIn:=xlValues, LookAt:=xlWhole)
  If Not c Is Nothing Then
    firstaddress = c.Address
    Do
      i = i + 1
      Iary(i) = c.Row
      Set c = .FindNext(c)
    Loop While Not c Is Nothing And c.Address <> firstaddress
  End If
End With
i = i + 1
Iary(i) = LR
For i = LBound(Iary) To UBound(Iary) - 1
  NR = Range("L" & Rows.Count).End(xlUp).Offset(1).Row
  Sp = Split(Range("F" & Iary(i)), " ")
  Range("L" & NR).Value = Sp(UBound(Sp))
  b = 0
  For a = Iary(i) To Iary(i + 1) - 1 Step 1
    If Cells(a, 1) = "" Then
      'do nothing
    ElseIf InStr(Cells(a, 1), "Order Nr") > 0 Then
      Sp = Split(Cells(a, 1), " ")
      Range("M" & NR).Value = Sp(2)
      Range("N" & NR).Value = Right(Sp(3), Len(Sp(3)) - 2)
      Range("O" & NR).Value = Sp(6)
    ElseIf IsNumeric(Cells(a, 1)) Then
      b = b + 1
      If b = 1 Then
        Range("P" & NR).Value = Cells(a, 1).Value
        Range("Q" & NR).Value = Cells(a, 3).Value
        Range("R" & NR).Value = Cells(a, 5).Value
        Sp = Split(Cells(a + 1, 2), " ")
        Range("S" & NR).Value = Sp(0)
        Sp = Split(Cells(a + 1, 3), " ")
        Range("T" & NR).Value = Sp(0)
        For aa = a To Iary(i + 1) - 1 Step 1
          If Cells(aa, 6) = "Delivery no." Then
            Range("U" & NR).Value = Cells(aa, 7).Value
            Exit For
          End If
        Next aa
      ElseIf b > 1 Then
        NR = NR + 1
        Range("L" & NR).Resize(, 4).Value = Range("L" & NR - 1).Resize(, 4).Value
        Range("P" & NR).Value = Cells(a, 1).Value
        Range("Q" & NR).Value = Cells(a, 3).Value
        Range("R" & NR).Value = Cells(a, 5).Value
        Sp = Split(Cells(a + 1, 2), " ")
        Range("S" & NR).Value = Sp(0)
        Sp = Split(Cells(a + 1, 3), " ")
        Range("T" & NR).Value = Sp(0)
        For aa = a To Iary(i + 1) - 1 Step 1
          If Cells(aa, 6) = "Delivery no." Then
            Range("U" & NR).Value = Cells(aa, 7).Value
            Exit For
          End If
        Next aa
      End If
    Else
      'do nothing
    End If
  Next a
  b = 0
Next i
Columns("L:U").AutoFit
Application.ScreenUpdating = True
End Sub


Then run the ReorgDataV2 macro.
 
Upvote 0
Hi
The code does work, but it is not putting the delivery note no.
Below is the original invoice. The invoice no is in a different column and this invoice has 2 pages. Please could you reset the code to read from this invoice.Also bear in mind that I have +/- 500 invoices in my spreadsheet all with different number of items, some 1 page and some 2 pages but there is a 3 row space between them after "Brazil".

Your assistance is greatly appreciated.
Thank You in advance.


<TABLE style="PADDING-RIGHT: 2pt; PADDING-LEFT: 2pt; FONT-SIZE: 10pt; FONT-FAMILY: Arial,Arial; BACKGROUND-COLOR: #ffffff" cellSpacing=0 cellPadding=0 border=1><TBODY><TR style="FONT-WEIGHT: bold; FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center"><TD>A</TD><TD>B</TD><TD>C</TD><TD>D</TD><TD>E</TD><TD>F</TD><TD>G</TD><TD>H</TD><TD>I</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">1</TD><TD> </TD><TD>P&A Sales Tax Invoice 9202325070</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">2</TD><TD> </TD><TD>Date:29.04.2011</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">3</TD><TD> </TD><TD>Customer number </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">4</TD><TD> </TD><TD style="TEXT-ALIGN: right">1331</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">5</TD><TD> </TD><TD>Your VAT Registration number</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">6</TD><TD> </TD><TD>ZA4350110971</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">7</TD><TD> </TD><TD>These parts and accessories are manufactured</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">8</TD><TD> </TD><TD>to General Motors specification </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">9</TD><TD>PO Box 585</TD><TD>Page 1 of 2</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">10</TD><TD style="TEXT-ALIGN: right">3610</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">11</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">12</TD><TD>Requirements:</TD><TD>Terms of payment 1 Calendar Month from Statement</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">13</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">14</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">15</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">16</TD><TD>Item</TD><TD> </TD><TD>Description </TD><TD> </TD><TD>Material</TD><TD> </TD><TD> </TD><TD> </TD><TD>ZAR</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">17</TD><TD> </TD><TD>Qty</TD><TD>Price</TD><TD>Price unit</TD><TD>Value</TD><TD>Trade Disc %</TD><TD>Trade Disc value</TD><TD>Net value</TD><TD>Total net value</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">18</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">19</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">20</TD><TD>Order No.: 0003367320 DD 28.04.2011; Order Type YSTK; Ship. Method ;Cust. Order no. 84317_PART1;Delivery note 9401632395 </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">21</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">22</TD><TD style="TEXT-ALIGN: right">1</TD><TD> </TD><TD>MOUNT ASM;ENG FRT</TD><TD> </TD><TD style="TEXT-ALIGN: right">93302281</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">23</TD><TD> </TD><TD>5 EA </TD><TD>130.84 ZAR</TD><TD>1 EA</TD><TD style="TEXT-ALIGN: right">654.2</TD><TD style="TEXT-ALIGN: right">0</TD><TD style="TEXT-ALIGN: right">0</TD><TD style="TEXT-ALIGN: right">130.84</TD><TD style="TEXT-ALIGN: right">654.2</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">24</TD><TD style="TEXT-ALIGN: right">2</TD><TD> </TD><TD>CLUTCH KIT</TD><TD> </TD><TD>TFK003</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">25</TD><TD> </TD><TD>2 EA </TD><TD>763.82 ZAR</TD><TD>1 EA</TD><TD style="TEXT-ALIGN: right">1527.64</TD><TD style="TEXT-ALIGN: right">0</TD><TD style="TEXT-ALIGN: right">0</TD><TD style="TEXT-ALIGN: right">763.82</TD><TD style="TEXT-ALIGN: right">1527.64</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">26</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">27</TD><TD> </TD><TD>These parts and accessories are manufactured</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">28</TD><TD> </TD><TD>to General Motors specification </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">29</TD><TD> </TD><TD>Page 2 of 2</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">30</TD><TD>PO Box 585</TD><TD>Sales Tax Invoice Doc.no./Date </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">31</TD><TD style="TEXT-ALIGN: right">3610</TD><TD>9202325070/29.04.2011</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">32</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">33</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">34</TD><TD>Item</TD><TD> </TD><TD>Description </TD><TD> </TD><TD>Material</TD><TD> </TD><TD> </TD><TD> </TD><TD>ZAR</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">35</TD><TD> </TD><TD>Qty</TD><TD>Price</TD><TD>Price unit</TD><TD>Value</TD><TD>Trade Disc %</TD><TD>Trade Disc value</TD><TD>Net value</TD><TD>Total net value</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">36</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">37</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">38</TD><TD style="TEXT-ALIGN: right">3</TD><TD> </TD><TD>STARTER MOTOR</TD><TD> </TD><TD style="TEXT-ALIGN: right">93614584</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">39</TD><TD> </TD><TD>1 EA </TD><TD>749.19 ZAR</TD><TD>1 EA</TD><TD style="TEXT-ALIGN: right">749.19</TD><TD style="TEXT-ALIGN: right">10.75- </TD><TD style="TEXT-ALIGN: right">80.54- </TD><TD style="TEXT-ALIGN: right">668.65</TD><TD style="TEXT-ALIGN: right">668.65</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">40</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD>Delivery no. </TD><TD style="TEXT-ALIGN: right">9.4E+09</TD><TD>Subtotal</TD><TD style="TEXT-ALIGN: right">4707.41</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">41</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">42</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">43</TD><TD>Items total </TD><TD> </TD><TD> </TD><TD> </TD><TD style="TEXT-ALIGN: right">4707.41</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">44</TD><TD>Output Tax </TD><TD> </TD><TD> </TD><TD> </TD><TD style="TEXT-ALIGN: right">0.14</TD><TD style="TEXT-ALIGN: right">4707.41</TD><TD> </TD><TD> </TD><TD style="TEXT-ALIGN: right">659.04</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">45</TD><TD>Final Amount </TD><TD> </TD><TD> </TD><TD> </TD><TD style="TEXT-ALIGN: right">5366.45</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">46</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">47</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">48</TD><TD>Directors: E.Lourencon* (President & Managing Director, GM Africa),J.M. Baepi, M.G. Sacke</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">49</TD><TD>*Brazil</TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR></TBODY></TABLE>
 
Upvote 0
DEBR,

The macro works correctly for your first set of screenshots.

But, it will not work correctly with your latest screenshot - the data has shifted left.


I am willing to look at an actual workbook containg the worksheet with the below screenshots. But, I will need many more samples of the Invoices below the screenshot shown. And, I will need to see beginning in colulm L, what the results should be from the first and second invoice.

You can upload your workbook to www.box.net and provide us with a link to your workbook.
 
Upvote 0
DEBR,

The macro works correctly for your first set of screenshots.

But, it will not work correctly with your latest screenshot - the data has shifted right.


I am willing to look at an actual workbook containg the worksheet with the below screenshots. But, I will need many more samples of the Invoices below the screenshot shown. And, I will need to see beginning in colulm L, what the results should be from the first and second invoice.

You can not give us screenshots[/u], you can upload your workbook to www.box.net and provide us with a link to your workbook.
 
Upvote 0
Hi

Please find file to the link below:
http://www.box.net/shared/nf5cp63mqo

I would like to thank you for helping me in advance. It would make my workload much lighter.

Thank You
icon7.gif
 
Upvote 0
DEBR,

The following is based on your latest workbook on Box.Net.


Sample data after the updated macro (only a few rows are shown from the total of 151 rows):


Excel Workbook
LMNOPQRSTU
1Invoice NoOrder NRDDOrder TypeLineDescriptionPart NoQtyPriceDelivery No
29202323920333964930.03.2011YVOR1PULLEY89794218701478.179401631530
39202323926334578604.04.2011YVOR1MOLDING A-ROOF9654310711139401631413
369202325068336754729.04.2011YEMG1BUSH;LEAF SPRING8970748260298.929401633034
379202325068336754729.04.2011YEMG2OUTLET ASM-WAT126057851327.389401633034
389202325069336754129.04.2011YEMG1BUSHING;LWR CONTROL ARM93395604258.589401633023
399202325070336732028.04.2011YSTK1CABLE ASM MANUAL TRANSM SHIFT LEVER933862671744.249401632395
409202325070336732028.04.2011YSTK2CABLE ASM;PARK BRAKE936013591168.319401632395
419202325070336732028.04.2011YSTK3HANDBRAKE CABLE - INTERMEDIATE93598311154.499401632395
429202325070336732028.04.2011YSTK4HAND BRAKE CABLE ASM-RR-R93597527193.169401632395
439202325070336732028.04.2011YSTK5HAND BRAKE CABLE ASM-RR-L93597526292.599401632395
449202325070336732028.04.2011YSTK60IPER BLADE - DRIVER SIDE931946321129.79401632395
459202325070336732028.04.2011YSTK7DISC PADS FRONT (SET)931887261366.939401632395
469202325070336732028.04.2011YSTK8TAIL LAMP WITH CIRCUIT;LH933138931168.789401632395
479202325070336732028.04.2011YSTK9MOUNT ASM;ENG FRT933022815130.849401632395
489202325070336732028.04.2011YSTK10CLUTCH KITTFK0032763.829401632395
499202325070336732028.04.2011YSTK11STARTER MOTOR936145841749.199401632395
509202325071336632428.04.2011YEMG1PIPE WATER OUTLET89760204701345.559401632168
519202325072335685214.04.2011YEMG1BLADE; WIPER89805378801179.349401631995
Sheet1





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).


1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Option Base 1
Sub ReorgDataV3()
' hiker95, 05/12/2011
' http://www.mrexcel.com/forum/showthread.php?t=549125
Dim c As Range, firstaddress As String
Dim a As Long, aa As Long, LR As Long, i As Long, NR As Long, b As Long
Dim Iary, Sp, myChar As String
Application.ScreenUpdating = False
myChar = Chr(160)
With Range("B1", Range("B" & Rows.Count).End(xlUp))
  .Replace What:=myChar, Replacement:=" ", LookAt:=xlPart, _
  SearchFormat:=False, ReplaceFormat:=False
End With
Columns("L:U").ClearContents
Range("L1:U1") = [{"Invoice No","Order NR","DD","Order Type","Line","Description","Part No","Qty","Price","Delivery No"}]
i = Application.CountIf(Columns(1), "*Brazil")
ReDim Iary(1 To i + 1)
For a = 1 To 10 Step 1
  If InStr(Cells(a, 2), "Invoice") > 0 Then
    Iary(1) = a
    Exit For
  End If
Next a
With Columns(1)
  i = 1
  Set c = .Find("*Brazil", LookIn:=xlValues, LookAt:=xlWhole)
  If Not c Is Nothing Then
    firstaddress = c.Address
    Do
      i = i + 1
      Iary(i) = c.Row + 4
      Set c = .FindNext(c)
    Loop While Not c Is Nothing And c.Address <> firstaddress
  End If
End With
For i = LBound(Iary) To UBound(Iary) - 1
  NR = Range("L" & Rows.Count).End(xlUp).Offset(1).Row
  Sp = Split(Range("B" & Iary(i)), " ")
  Range("L" & NR).Value = Sp(UBound(Sp))
  b = 0
  For a = Iary(i) To Iary(i + 1) - 1 Step 1
    If Cells(a, 1) = "" Then
      'do nothing
    ElseIf InStr(Cells(a, 1), "Order No") > 0 Then
      Sp = Split(Cells(a, 1), " ")
      Range("M" & NR).Value = Sp(2)
      Range("N" & NR).Value = Left(Sp(4), Len(Sp(4)) - 1)
      Range("O" & NR).Value = Left(Sp(7), Len(Sp(7)) - 1)
    ElseIf IsNumeric(Cells(a, 1)) Then
      b = b + 1
      If b = 1 Then
        Range("P" & NR).Value = Cells(a, 1).Value
        Range("Q" & NR).Value = Cells(a, 3).Value
        Range("R" & NR).Value = Cells(a, 5).Value
        Range("S" & NR).Value = Left(Cells(a + 1, 2), Len(Cells(a + 1, 2)) - 3)
        Sp = Split(Cells(a + 1, 3), " ")
        Range("T" & NR).Value = Sp(0)
        For aa = a To Iary(i + 1) - 1 Step 1
          If InStr(Cells(aa, 6), "Delivery no.") > 0 Then
            Range("U" & NR).Value = Cells(aa, 7).Value
            Exit For
          End If
        Next aa
      ElseIf b > 1 Then
        NR = NR + 1
        Range("L" & NR).Resize(, 4).Value = Range("L" & NR - 1).Resize(, 4).Value
        Range("P" & NR).Value = Cells(a, 1).Value
        Range("Q" & NR).Value = Cells(a, 3).Value
        Range("R" & NR).Value = Cells(a, 5).Value
        Sp = Split(Cells(a + 1, 2), " ")
        Range("S" & NR).Value = Sp(0)
        Sp = Split(Cells(a + 1, 3), " ")
        Range("T" & NR).Value = Sp(0)
        For aa = a To Iary(i + 1) - 1 Step 1
          If InStr(Cells(aa, 6), "Delivery no.") > 0 Then
            Range("U" & NR).Value = Cells(aa, 7).Value
            Exit For
          End If
        Next aa
        Range("U" & NR).Value = Range("U" & NR - 1).Value
      End If
    Else
      'do nothing
    End If
  Next a
  b = 0
Next i
Columns("L:U").AutoFit
Application.ScreenUpdating = True
End Sub


Then run the ReorgDataV3 macro.
 
Upvote 0
Thank you very much, it works perfectly.
If its not to much to ask if you could add Cust Order No to the table.

eg:Cust Ord No
DEN81396

icon10.gif
Thank You again for all your help.
 
Upvote 0
DEBR,

If its not to much to ask if you could add Cust Order No to the table.

I did ask for (which you did not supply):
And, I will need to see beginning in colulm L, what the results should be from the first and second invoice.

From the last workbook on Box.Net, I will need a screenshot: manually completed by you, beginning in column L, cell L1, all the titles, and beginning in L2, the data from the first two Invoices.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,687
Members
449,117
Latest member
Aaagu

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