+ Reply to Thread
Results 1 to 7 of 7

Editing BOM automatically

Hybrid View

  1. #1
    Registered User
    Join Date
    11-15-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    17

    Editing BOM automatically

    Hello!

    Need your help guys. Just wondering if this is possible (see bom1 and bom2 screen shots)

    Basically what needs to be done is:

    Detect material change in column F, add 2 empty rows between different materials, add WEIGHT: and do weight sum in Column G..... and so on for the entire spreadsheet.
    At the very end need to See entire WEIGHT for all parts.

    Any ideas? Thanks in advance!
    Alex.
    Attached Images Attached Images

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,760

    Re: Editing BOM automatically

    Does it need to be in that format? If you add a column for total weight for each type of material, it would be easy to do this with just formulas. If you really need this format with rows inserted then a macro will probably be easier. It would have to be set up to run anytime the worksheet changed.

    Also, please see my editorial about screenshots below...
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    11-15-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    17

    Question Re: Editing BOM automatically

    Thanks,

    Please take a look at the original spread sheet that Inventor spits out, I`m using macros (Ctrl+shift+F) to change it a little bit. Then if you run the macro below it will add 2 rows between materials...
    My question is how to add WEIGHT: in F column and sum weight in G column???

    Sub detect_mat()
    Dim last As Long
    Dim x As Long
    last = Cells(Rows.Count, "e").End(xlUp).Row
    For x = 3 To last * 4 Step 1
    If Cells(x, 5).Value <> Cells(x + 1, 5).Value Then
    Rows(x + 1).Select
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        x = x + 2
        'HOW TO ADD WEIGHT?
        'HOW TO ADD SUM WEIGHT?
    End If
    Next
    End Sub
    Attached Files Attached Files
    Last edited by achmidt; 11-16-2011 at 03:26 PM.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,760

    Re: Editing BOM automatically

    Private Sub test()
    
       Dim x As Long
       Dim SumWeight As Double
       
       For x = 3 To 40
       
          SumWeight = SumWeight + Cells(x, 2)
       
          If Cells(x, 1).Value <> Cells(x + 1, 1).Value Then
              Rows(x + 1).Select
          
              Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
              Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
              
              'HOW TO ADD WEIGHT?
              Cells(x + 1, 6) = "WEIGHT"
              'HOW TO ADD SUM WEIGHT?
              Cells(x + 1, 7) = SumWeight
              SumWeight = 0
              
              x = x + 2
              
          End If
          
       Next
    
    End Sub

  5. #5
    Registered User
    Join Date
    11-15-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    17

    Question Re: Editing BOM automatically

    Great ! Thank you.

    The other question I had, how to format cells (add borders) using vba? I guess I need to detect the lowest right corner.... how I can do that? For this particular document it is 132, but all documents are different lengths.
    After downloading document please goto macros and run WEIGHTLIST1

    Sub Borders()
    '
    '
        Range("A1:I132").Select
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With Selection.Borders(xlInsideVertical)
            .LineStyle = xlContinuous
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With Selection.Borders(xlInsideHorizontal)
            .LineStyle = xlContinuous
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThin
        End With
    End Sub
    Attached Files Attached Files

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Editing BOM automatically

    Instead of

    If Cells(x, 1).Value <> Cells(x + 1, 1).Value Then
     Rows(x + 1).select
          
     Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
     Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    you can use:

     
    If Cells(x, 1).Value <> Cells(x + 1, 1).Value Then
      Rows(x + 1).Resize(2).Insert
    But if adding a simple column:

    Private Sub test()
     sn = Cells(1).CurrentRegion.Resize(, 1).Offset(, 9)
     sq = Cells(1).CurrentRegion.Offset(, 1).Resize(, 5)
     sq(1, 1) = 0
       
     For j = 3 To UBound(sn) - 1
      sq(1, 1) = sq(1, 1) + sq(j, 1)
       
      If sq(j, 5) <> sq(j + 1, 5) Then
       sn(j, 1) = sq(1, 1)
       sq(1, 1) = 0
       j = j + 1
      End If
     Next
       Cells(1, 9).Resize(UBound(sn)) = sn
    End Sub
    Last edited by snb; 11-17-2011 at 05:42 PM.



  7. #7
    Registered User
    Join Date
    11-15-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Editing BOM automatically

    Quote Originally Posted by snb View Post
    Instead of

    If Cells(x, 1).Value <> Cells(x + 1, 1).Value Then
     Rows(x + 1).select
          
     Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
     Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    you can use:

     
    If Cells(x, 1).Value <> Cells(x + 1, 1).Value Then
      Rows(x + 1).Resize(2).Insert
    Thanks snb, it does works faster now.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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