Multiple lookup data

soumen21

New Member
Joined
Aug 16, 2019
Messages
29
I have a sheet1 like like this

Base PartComponent NumberComponent DescriptionSubclass
ABCD42G1001-0002NutTighteners
DCBA42G1001-0109ScrewsTighteners

In Sheet2 I have multiple manufacturers for 42G1001-0002, like
UPLOADED CPNUPLOADED PARTUPLOADED MANUFACTURER
42G1001-0002CR10-1002-FKASJ PTE LTD
42G1001-0002RK73H1ETTP1002FKOA SPEER ELECTRONICS INC
42G1001-0002RK73H1ETTPD1002FKOA SPEER ELECTRONICS INC

I want to have sheet 1 look like

Base PartComponent NumberPart NumberManufacturerComponent DescriptionSubclass
ABCD42G1001-0002CR10-1002-FKASJ PTE LTDNutTighteners
ABCD42G1001-0002RK73H1ETTP1002FKOA SPEER ELECTRONICS INCNutTighteners
ABCD42G1001-0002RK73H1ETTPD1002FKOA SPEER ELECTRONICS INCNutTighteners
DCBA42G1001-0109ScrewsTighteners

Basically, I want to find all the parts numbers and manufacturers under 42G1001-0002 listed in Sheet2 and add in sheet1. The process continues for other parts as well.

Can you help how to do?


Thanks in advance.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
This seems to work:
VBA Code:
Sub InsertData()
    Application.ScreenUpdating = False
    Dim rng As Range, desWS As Worksheet, srcWS As Worksheet
    Sheets.Add after:=Sheets(Sheets.Count)
    ActiveSheet.Name = "temp"
    Set desWS = Sheets("Sheet1")
    Set srcWS = Sheets("Sheet2")
    For Each rng In desWS.Range("B2", desWS.Range("B" & Rows.Count).End(xlUp))
        With srcWS
            .Range("A1").CurrentRegion.AutoFilter 1, rng
            .AutoFilter.Range.Offset(1).Copy Sheets("temp").Cells(Sheets("temp").Rows.Count, "B").End(xlUp).Offset(1)
            If .[subtotal(103,A:A)] - 1 > 0 Then
                Sheets("temp").Cells(Sheets("temp").Rows.Count, "A").End(xlUp).Offset(1).Resize(.[subtotal(103,A:A)] - 1) = rng.Offset(, -1)
                Sheets("temp").Cells(Sheets("temp").Rows.Count, "E").End(xlUp).Offset(1).Resize(.[subtotal(103,A:A)] - 1, 2) = Array(rng.Offset(, 1), rng.Offset(, 2))
            Else
                Sheets("temp").Cells(Sheets("temp").Rows.Count, "A").End(xlUp).Offset(1).Resize(, 2) = Array(rng.Offset(, -1), rng)
                Sheets("temp").Cells(Sheets("temp").Rows.Count, "E").End(xlUp).Offset(1).Resize(, 2) = Array(rng.Offset(, 1), rng.Offset(, 2))
            End If
        End With
    Next rng
    srcWS.Range("A1").AutoFilter
    With desWS
        .UsedRange.ClearContents
        .Range("A1").Resize(, 6) = Array("Base Part", "Component Number", "Part Number", "Manufacturer", "Component Description", "Subclass")
        Sheets("temp").Range("A2", Sheets("temp").Range("F" & Rows.Count).End(xlUp)).Copy .Range("A2")
        .Columns.AutoFit
        Application.DisplayAlerts = False
        Sheets("temp").Delete
        Application.DisplayAlerts = True
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
This seems to work:
VBA Code:
Sub InsertData()
    Application.ScreenUpdating = False
    Dim rng As Range, desWS As Worksheet, srcWS As Worksheet
    Sheets.Add after:=Sheets(Sheets.Count)
    ActiveSheet.Name = "temp"
    Set desWS = Sheets("Sheet1")
    Set srcWS = Sheets("Sheet2")
    For Each rng In desWS.Range("B2", desWS.Range("B" & Rows.Count).End(xlUp))
        With srcWS
            .Range("A1").CurrentRegion.AutoFilter 1, rng
            .AutoFilter.Range.Offset(1).Copy Sheets("temp").Cells(Sheets("temp").Rows.Count, "B").End(xlUp).Offset(1)
            If .[subtotal(103,A:A)] - 1 > 0 Then
                Sheets("temp").Cells(Sheets("temp").Rows.Count, "A").End(xlUp).Offset(1).Resize(.[subtotal(103,A:A)] - 1) = rng.Offset(, -1)
                Sheets("temp").Cells(Sheets("temp").Rows.Count, "E").End(xlUp).Offset(1).Resize(.[subtotal(103,A:A)] - 1, 2) = Array(rng.Offset(, 1), rng.Offset(, 2))
            Else
                Sheets("temp").Cells(Sheets("temp").Rows.Count, "A").End(xlUp).Offset(1).Resize(, 2) = Array(rng.Offset(, -1), rng)
                Sheets("temp").Cells(Sheets("temp").Rows.Count, "E").End(xlUp).Offset(1).Resize(, 2) = Array(rng.Offset(, 1), rng.Offset(, 2))
            End If
        End With
    Next rng
    srcWS.Range("A1").AutoFilter
    With desWS
        .UsedRange.ClearContents
        .Range("A1").Resize(, 6) = Array("Base Part", "Component Number", "Part Number", "Manufacturer", "Component Description", "Subclass")
        Sheets("temp").Range("A2", Sheets("temp").Range("F" & Rows.Count).End(xlUp)).Copy .Range("A2")
        .Columns.AutoFit
        Application.DisplayAlerts = False
        Sheets("temp").Delete
        Application.DisplayAlerts = True
    End With
    Application.ScreenUpdating = True
End Sub
Thank you. It worked
 
Upvote 0
You are very welcome. :)
 
Upvote 0

Forum statistics

Threads
1,215,330
Messages
6,124,310
Members
449,152
Latest member
PressEscape

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