VBA to split data

Akira181

Board Regular
Joined
Mar 23, 2010
Messages
67
Office Version
  1. 365
Platform
  1. Windows
I have a excel bill of materials for a machine extracted from my works database that's over 31k rows long and quite messy in presentation. There's blank rows in between, some cells are merged, some cells are blank but the row contains information needed, etc.

The information is divided into assemblies, then each assembly split into levels. All assemblies are "Level 1" as indicated in column A. I would like a macro that is able to copy all rows from the first "1" in column A up to (but not including) the next "1" in Column A and paste it into a new worksheet. I would like to do this for each assembly and also remove all the blank rows inbetween so it's easier to read.

I was trying to follow this thread, VBA copy rows between two specific values, but haven't been able to get it to work for my needs.. Can someone help a total VBA novice?

BOM.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAI
19LevelBalloonComponent Item No.Quantity Per Order Quantity Per UnitU/MExtended DescriptionDrawing #RevisionDrawing Size Item Group
20
21
22
23101xxxxxx1.001.00 EAProject Number 123 - Assembly ABCDE Parts
24
25
262 01AXXXXXXXXX1.001.00 EAAAA123456 D Parts
27 A
28
293200XXXXXXXXX3.003.00 EABBB123456 D Parts
30 A
31
32
3341XXXXXXXXX3.001.00 eaCCC123456 D Parts
34 A
35
36
37
38701XXXXXXXXX6.001.00 EADDD123456 Parts
39
40
41
42DDD1
43
44
45Manufacturer:VendorMFG CODEDDD2
46
47701XXXXXXXXX0.000.00 lfEEE123456 Raw Materials
48
49
50101xxxxxx1.001.00 EAProject Number 123 - Assembly FGH Parts
51
52
532004104417026.002.00 EAFFF10579002 Parts
54
BOM (2)


So ideally, Rows 23/24 to 47/48 would be copied to a new worksheet and the blank rows and cell merges removed if possible (nice to have, can be ignored if it's difficult to do). Then Rows 50/51 to the last row prior to the next "1" gets copied to a different worksheet, and so on.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Is there another way to export your bill of materials from the database? I unmerged the cells, deleted all the empty columns, shifted the headers to the right one column, deleted more empty columns, shifted the revisions up one row, and then deleted the empty rows to make it look like below...
Book1
ABCDEFGHIJK
19LevelBalloonComponent Item No.Quantity Per Order Quantity Per UnitU/MExtended DescriptionDrawing #RevisionDrawing Size Item Group
2011xxxxxx11 EAProject Number 123 - Assembly ABCDE Parts
212 01AXXXXXXXXX11 EAAAA123456 A D Parts
223200XXXXXXXXX33 EABBB123456 A D Parts
2341XXXXXXXXX31 eaCCC123456 A D Parts
2471XXXXXXXXX61 EADDD123456 Parts
25DDD1
26Manufacturer:VendorMFG CODEDDD2
2771XXXXXXXXX00 lfEEE123456 Raw Materials
2811xxxxxx11 EAProject Number 123 - Assembly FGH Parts
29241044170262 EAFFF10579002 Parts
Sheet2

On a larger scale, the lengthy part would be deleting rows. A macro could be written to do that pretty easily.

I am unsure why some cells have extra spaces (revision column), and I am not sure what is going on in rows 25 and 26. If you could get a cleaner export, the spreadsheet would be much easier to digest, and extracting the level 1 assemblies would be easier and cleaner.

Doug
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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