Quantcast
Viewing all articles
Browse latest Browse all 29110

Excel: Combine Sheets based on Part Number and Inventory

I have two sheets of data. One has the Part Number that is needed for a PO.

(See Sample Attached)

On the second sheet, it was originally formatted the same way, minus the 3rd column that has the date available, currently I am using this

Code:

Sub ExpandRows()
    Dim dat As Variant
    Dim i As Long
    Dim rw As Range
    Dim rng As Range

    Set rng = ActiveSheet.UsedRange
    dat = rng

    ' Loop thru your data, starting at the last row
    For i = UBound(dat, 1) To 2 Step -1
        ' If Quantity > 1
        If dat(i, 3) > 1 Then
            ' Insert rows to make space
            Set rw = rng.Rows(i).EntireRow
            rw.Offset(1, 0).Resize(dat(i, 3) - 1).Insert
            ' copy row data down
            rw.Copy rw.Offset(1, 0).Resize(dat(i, 3) - 1)
            ' set Quantity to 1
            rw.Cells(1, 3).Resize(dat(i, 3), 1) = 1
        End If
    Next
End Sub

This splits up the combined quantity into individual lines, this does not have to be done, just thinking it would be that much easier.

What I am trying to do is create a new worksheet for each Part Number (Line) from Worksheet 1 and using my example pull 3 lines from Worksheet 2 with the matching Part Number and the date available.

I have tried to search around, just not sure what I am looking for. Any suggestions or just a nudge in the right direction would be great.

Attached Files
Image may be NSFW.
Clik here to view.
File Type: xlsx
Sample.xlsx (56.1 KB)

Viewing all articles
Browse latest Browse all 29110

Trending Articles