Mr. Excel,
I am attempting to find/write some VBA code for looking at a manufacturing Bill fo Material for a finished product, and deleting any Bill of Material Lines below purchased parts. Assuming the "Line#" heading below is in cell A1, can you help me with some VBA code for this? The "action" shows which lines should be deleted through the code. "lvl" stands for the level on an indented bill of material. Level 0 is the finished product, and levels 1 through 4 are different assemblies of the product and purchased parts which make up the finished product. A level 4 would be a part or subassembly which is manufactured into a level 3, and a level 3 into a level 2, etc. "MP" is whether a part is manufactured or purchased. As you can see, the first line which would be deleted is line 10, because it is a single line bill of material under a purchased part.
Everything below the level 1 purchased part (line 20) until the next level 1 part (line 30) would be deleted because this circuit board (part number 1803260.6</SPAN>) is no longer being manfuactured in-house, but is being purchased as an assembly from a third party. I am using Excel 2010 on Windows 7. I am thinking I will need a some looping code which looks at the 2 parameters, the "MP" and the "lvl". in the case of the line 20 purchased part, it would delete any lines below it which have an "lvl" which is > its lvl (1), until it reaches an lvl which = the lvl of this purchased part (in this case 1). It will then move on to the next line and re-evaluate until it reaches the end of the data set.
thanks so much for your help!
[TABLE="width: 397"]
<TBODY>[TR]
[TD]line#</SPAN>[/TD]
[TD]lvl</SPAN>[/TD]
[TD]MP</SPAN>[/TD]
[TD]part number</SPAN>[/TD]
[TD]description</SPAN>[/TD]
[TD]action</SPAN>[/TD]
[/TR]
[TR]
[TD]1</SPAN>[/TD]
[TD]0</SPAN>[/TD]
[TD]M</SPAN>[/TD]
[TD]1954321</SPAN>[/TD]
[TD]Calculator</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]2</SPAN>[/TD]
[TD]1</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1123544</SPAN>[/TD]
[TD]Battery</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]3</SPAN>[/TD]
[TD]1</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1654123</SPAN>[/TD]
[TD]Screws</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]4</SPAN>[/TD]
[TD]1</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1156211</SPAN>[/TD]
[TD]Front cover plate</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]5</SPAN>[/TD]
[TD]1</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1156112</SPAN>[/TD]
[TD]Back cover plate</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]6</SPAN>[/TD]
[TD]1</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1156412</SPAN>[/TD]
[TD]packaging</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]7</SPAN>[/TD]
[TD]1</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1654232</SPAN>[/TD]
[TD]instruction manual</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]8</SPAN>[/TD]
[TD]1</SPAN>[/TD]
[TD]M</SPAN>[/TD]
[TD]1149837</SPAN>[/TD]
[TD]battery housing</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]9</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1287622.3</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]10</SPAN>[/TD]
[TD]3</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]2425407.6</SPAN>[/TD]
[TD] [/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]13</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]M</SPAN>[/TD]
[TD]1838763.5</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]14</SPAN>[/TD]
[TD]3</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1976548.8</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]15</SPAN>[/TD]
[TD]4</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1114334.1</SPAN>[/TD]
[TD] [/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]16</SPAN>[/TD]
[TD]4</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1252119.4</SPAN>[/TD]
[TD] [/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]17</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1389904.7</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]20</SPAN>[/TD]
[TD]1</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1803260.6</SPAN>[/TD]
[TD]Circuit board</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]21</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]m</SPAN>[/TD]
[TD]1941045.9</SPAN>[/TD]
[TD]board</SPAN>[/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]22</SPAN>[/TD]
[TD]3</SPAN>[/TD]
[TD]p</SPAN>[/TD]
[TD]2078831.2</SPAN>[/TD]
[TD]copper conductors</SPAN>[/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]23</SPAN>[/TD]
[TD]3</SPAN>[/TD]
[TD]m</SPAN>[/TD]
[TD]2216616.5</SPAN>[/TD]
[TD]switches</SPAN>[/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]24</SPAN>[/TD]
[TD]4</SPAN>[/TD]
[TD]p</SPAN>[/TD]
[TD]2354401.8</SPAN>[/TD]
[TD]switch cover</SPAN>[/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]25</SPAN>[/TD]
[TD]4</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]2492187.1</SPAN>[/TD]
[TD]inner switch</SPAN>[/TD]
[TD]delete[/TD]
[/TR]
[TR]
[TD]26</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]m</SPAN>[/TD]
[TD]2629972.4</SPAN>[/TD]
[TD] [/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]27</SPAN>[/TD]
[TD]3</SPAN>[/TD]
[TD]p</SPAN>[/TD]
[TD]2767757.7</SPAN>[/TD]
[TD] [/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]28</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]p</SPAN>[/TD]
[TD]2905543</SPAN>[/TD]
[TD] [/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]29</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]p</SPAN>[/TD]
[TD]3043328.3</SPAN>[/TD]
[TD] [/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]30</SPAN>[/TD]
[TD]1</SPAN>[/TD]
[TD]m</SPAN>[/TD]
[TD]3181113.6</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]31</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]p</SPAN>[/TD]
[TD]3318898.9</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
</TBODY><COLGROUP><COL><COL><COL><COL><COL><COL></COLGROUP>[/TABLE]
I am attempting to find/write some VBA code for looking at a manufacturing Bill fo Material for a finished product, and deleting any Bill of Material Lines below purchased parts. Assuming the "Line#" heading below is in cell A1, can you help me with some VBA code for this? The "action" shows which lines should be deleted through the code. "lvl" stands for the level on an indented bill of material. Level 0 is the finished product, and levels 1 through 4 are different assemblies of the product and purchased parts which make up the finished product. A level 4 would be a part or subassembly which is manufactured into a level 3, and a level 3 into a level 2, etc. "MP" is whether a part is manufactured or purchased. As you can see, the first line which would be deleted is line 10, because it is a single line bill of material under a purchased part.
Everything below the level 1 purchased part (line 20) until the next level 1 part (line 30) would be deleted because this circuit board (part number 1803260.6</SPAN>) is no longer being manfuactured in-house, but is being purchased as an assembly from a third party. I am using Excel 2010 on Windows 7. I am thinking I will need a some looping code which looks at the 2 parameters, the "MP" and the "lvl". in the case of the line 20 purchased part, it would delete any lines below it which have an "lvl" which is > its lvl (1), until it reaches an lvl which = the lvl of this purchased part (in this case 1). It will then move on to the next line and re-evaluate until it reaches the end of the data set.
thanks so much for your help!
[TABLE="width: 397"]
<TBODY>[TR]
[TD]line#</SPAN>[/TD]
[TD]lvl</SPAN>[/TD]
[TD]MP</SPAN>[/TD]
[TD]part number</SPAN>[/TD]
[TD]description</SPAN>[/TD]
[TD]action</SPAN>[/TD]
[/TR]
[TR]
[TD]1</SPAN>[/TD]
[TD]0</SPAN>[/TD]
[TD]M</SPAN>[/TD]
[TD]1954321</SPAN>[/TD]
[TD]Calculator</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]2</SPAN>[/TD]
[TD]1</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1123544</SPAN>[/TD]
[TD]Battery</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]3</SPAN>[/TD]
[TD]1</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1654123</SPAN>[/TD]
[TD]Screws</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]4</SPAN>[/TD]
[TD]1</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1156211</SPAN>[/TD]
[TD]Front cover plate</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]5</SPAN>[/TD]
[TD]1</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1156112</SPAN>[/TD]
[TD]Back cover plate</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]6</SPAN>[/TD]
[TD]1</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1156412</SPAN>[/TD]
[TD]packaging</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]7</SPAN>[/TD]
[TD]1</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1654232</SPAN>[/TD]
[TD]instruction manual</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]8</SPAN>[/TD]
[TD]1</SPAN>[/TD]
[TD]M</SPAN>[/TD]
[TD]1149837</SPAN>[/TD]
[TD]battery housing</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]9</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1287622.3</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]10</SPAN>[/TD]
[TD]3</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]2425407.6</SPAN>[/TD]
[TD] [/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]13</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]M</SPAN>[/TD]
[TD]1838763.5</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]14</SPAN>[/TD]
[TD]3</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1976548.8</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]15</SPAN>[/TD]
[TD]4</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1114334.1</SPAN>[/TD]
[TD] [/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]16</SPAN>[/TD]
[TD]4</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1252119.4</SPAN>[/TD]
[TD] [/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]17</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1389904.7</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]20</SPAN>[/TD]
[TD]1</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]1803260.6</SPAN>[/TD]
[TD]Circuit board</SPAN>[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]21</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]m</SPAN>[/TD]
[TD]1941045.9</SPAN>[/TD]
[TD]board</SPAN>[/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]22</SPAN>[/TD]
[TD]3</SPAN>[/TD]
[TD]p</SPAN>[/TD]
[TD]2078831.2</SPAN>[/TD]
[TD]copper conductors</SPAN>[/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]23</SPAN>[/TD]
[TD]3</SPAN>[/TD]
[TD]m</SPAN>[/TD]
[TD]2216616.5</SPAN>[/TD]
[TD]switches</SPAN>[/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]24</SPAN>[/TD]
[TD]4</SPAN>[/TD]
[TD]p</SPAN>[/TD]
[TD]2354401.8</SPAN>[/TD]
[TD]switch cover</SPAN>[/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]25</SPAN>[/TD]
[TD]4</SPAN>[/TD]
[TD]P</SPAN>[/TD]
[TD]2492187.1</SPAN>[/TD]
[TD]inner switch</SPAN>[/TD]
[TD]delete[/TD]
[/TR]
[TR]
[TD]26</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]m</SPAN>[/TD]
[TD]2629972.4</SPAN>[/TD]
[TD] [/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]27</SPAN>[/TD]
[TD]3</SPAN>[/TD]
[TD]p</SPAN>[/TD]
[TD]2767757.7</SPAN>[/TD]
[TD] [/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]28</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]p</SPAN>[/TD]
[TD]2905543</SPAN>[/TD]
[TD] [/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]29</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]p</SPAN>[/TD]
[TD]3043328.3</SPAN>[/TD]
[TD] [/TD]
[TD]delete</SPAN>[/TD]
[/TR]
[TR]
[TD]30</SPAN>[/TD]
[TD]1</SPAN>[/TD]
[TD]m</SPAN>[/TD]
[TD]3181113.6</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]31</SPAN>[/TD]
[TD]2</SPAN>[/TD]
[TD]p</SPAN>[/TD]
[TD]3318898.9</SPAN>[/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
</TBODY><COLGROUP><COL><COL><COL><COL><COL><COL></COLGROUP>[/TABLE]