+ Reply to Thread
Results 1 to 10 of 10

Flat bom to multilevel bom

Hybrid View

kcoates Flat bom to multilevel bom 11-19-2014, 12:56 PM
natefarm Re: Flat bom to multilevel bom 11-20-2014, 01:12 PM
kcoates Re: Flat bom to multilevel bom 11-20-2014, 02:32 PM
natefarm Re: Flat bom to multilevel bom 11-20-2014, 03:12 PM
kcoates Re: Flat bom to multilevel bom 11-20-2014, 03:45 PM
natefarm Re: Flat bom to multilevel bom 11-20-2014, 05:52 PM
kcoates Re: Flat bom to multilevel bom 11-20-2014, 06:20 PM
natefarm Re: Flat bom to multilevel bom 11-21-2014, 12:52 PM
kcoates Re: Flat bom to multilevel bom 11-21-2014, 01:15 PM
natefarm Re: Flat bom to multilevel bom 11-21-2014, 06:06 PM
  1. #1
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Flat bom to multilevel bom

    Give this a try. It will clear Sheet2 and create the multi-level structure there.

    Option Explicit
    Dim s1Row As Long, s1Col As Long, s1End As Long
    Dim s2 As Worksheet, s2Row As Long, s2Col As Long, s2PartFnd As Range
    
    Sub BuildPartLevels()
        Sheets("Sheet1").Select
        Set s2 = Sheets("Sheet2")
        s1Row = 2
        s2Row = 2
    
        With s2
            .Cells.ClearContents
            .Cells.HorizontalAlignment = xlLeft
    
            ' Get top levels first
            Do Until Cells(s1Row, 3).Value = ""
                If Cells(s1Row, 3).Value = "END ITEM" Then
                    .Cells(s2Row, 1).Value = Cells(s1Row, 1).Value ' Part num
                    .Cells(s2Row, 2).Value = Cells(s1Row, 2).Value ' Desc
                    .Cells(s2Row, 3).Value = Cells(s1Row, 4).Value ' Qty
                    .Cells(s2Row, 3).HorizontalAlignment = xlRight
                    s2Row = s2Row + 1
                End If
                s1Row = s1Row + 1
            Loop
            If s2Row = 2 Then
                MsgBox "Top level items not found"
                Exit Sub
            End If
            s1End = s1Row - 1
        
            ' Start on sub-levels
            s1Row = 2
            s1Col = 3
            Do Until s1Row > s1End ' Loop through assembly column sets
                Do Until s1Row > s1End ' Loop through rows
                    If Cells(s1Row, s1Col).Value <> "END ITEM" And Cells(s1Row, s1Col).Value <> "" Then
                        Set s2PartFnd = .Range("A1")
                        Set s2PartFnd = .Cells.Find(What:=Cells(s1Row, s1Col).Value, After:=s2PartFnd, LookAt:=xlWhole)
                        If s2PartFnd Is Nothing Then
                            MsgBox Cells(s1Row, s1Col).Value & " not found in " & .Name & ". Continuing."
                        Else
    FoundPart:
                            s2Row = s2PartFnd.Row + 1
                            s2Col = s2PartFnd.Column + 1
                            .Rows(s2Row).Insert
                            .Rows(s2Row).HorizontalAlignment = xlLeft
                            .Cells(s2Row, s2Col).Value = Cells(s1Row, 1).Value
                            .Cells(s2Row, s2Col + 1).Value = Cells(s1Row, 2).Value
                            .Cells(s2Row, s2Col + 2).Value = Cells(s1Row, s1Col + 1).Value
                            .Cells(s2Row, s2Col + 2).HorizontalAlignment = xlRight
    
                            Set s2PartFnd = .Cells.Find(What:=Cells(s1Row, s1Col).Value, After:=s2PartFnd, LookAt:=xlWhole)
                            If s2PartFnd.Row > s2Row Then ' the part appears in more than one higher level
                                GoTo FoundPart
                            End If
                        End If
                    End If
                    s1Row = s1Row + 1
                Loop
                s1Row = 2
                s1Col = s1Col + 2 ' Next assembly column
                If Cells(s1Row, s1Col).Value = "" Then ' Find first part in the next assembly column
                    s1Row = Cells(s1Row, s1Col).End(xlDown).Row
                End If
            Loop
            .Columns("A:" & Left(.Cells.SpecialCells(xlCellTypeLastCell).Address(, False), 1)).ColumnWidth = 15
            .Select
        End With
    End Sub
    Last edited by natefarm; 11-21-2014 at 06:12 PM. Reason: Fixed alignment problem
    Acts 4:12
    Salvation is found in no one else, for there is no other name under heaven given to mankind by which we must be saved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Using Multilevel Lists in VBA
    By drstrings in forum Word Programming / VBA / Macros
    Replies: 0
    Last Post: 08-07-2013, 08:45 PM
  2. multilevel line graph with different value
    By bertique in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 06-14-2013, 03:36 AM
  3. MultiLevel BOM Comparison
    By gopinathtt in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 12-27-2012, 07:33 PM
  4. Multilevel Ranges
    By Cheer-Phil-ly in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-30-2005, 05:20 PM
  5. Multilevel Sorting?
    By Mike in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-18-2005, 11:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1