How to return multiple row matches for a list of unique values

Rosie1900

New Member
Joined
Feb 15, 2018
Messages
4
I have a workbook with multiple worksheets.
1st sheet contains data - 000's of rows with many cols (one of which is txn #)
On this sheet, a given txn # may have multiple rows associated with it (the txn # is the same but each row has specific data).
2nd sheet has list of 20 unique txn #s
On 3rd sheet, I want to extract all of the rows (from 1st sheet) per each txn # and continue repeating for each of the 20 txn #s .
Essentially I want to take first txn # value from 2nd sheet and extract all row matches from 1st sheet onto the 3rd sheet.
Then do the same with the second txn # value from 2nd sheet, and so on...
Is this possible with excel?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi & welcome to the board.
How about
Code:
Sub Copydata()

   Dim Ws1 As Worksheet
   Dim Ws2 As Worksheet
   Dim Ws3 As Worksheet
   Dim Cl As Range
   
   Set Ws1 = Sheets("[COLOR=#ff0000]Sheet1[/COLOR]")
   Set Ws2 = Sheets("[COLOR=#ff0000]Sheet2[/COLOR]")
   Set Ws3 = Sheets("[COLOR=#ff0000]Sheet3[/COLOR]")
   
   If Ws1.AutoFilterMode Then Ws1.AutoFilterMode = False
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws2.Range("A2", Ws2.Range("A" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then
            .Add Cl.Value, Nothing
            Ws1.Range("A1").AutoFilter 1, Cl.Value
            Ws1.UsedRange.Offset(1).SpecialCells(xlVisible).Copy _
               Ws3.Range("A" & Rows.Count).End(xlUp).Offset(1)
         End If
      Next Cl
   End With
   Ws1.AutoFilterMode = False
      
End Sub
Change sheet names in red to suit.
As you haven't given us much info, I've assumed that the txn#s are in col A & that you have a header row in row 1
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,748
Messages
6,180,721
Members
452,995
Latest member
isldboy

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