Question : Macro to select data

In the attached Excel file, Sheet1 contains data, and Sheet2 contains a list of numbers in Col A.  A macro is needed to look at each number in Sheet2 Col A and find a match on Sheet1 Col A.  If a match is found, copy the data (found on Sheet1) relating to that number onto to Sheet3.
Attachments:
 
Tesst
 

Answer : Macro to select data

Hi Rishi,

Try the following macro.


Let me knwo if you have any issues,

- Ardhendu
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
Option Explicit

Sub Macro4()

Dim ws1     As Worksheet, _
    ws2     As Worksheet, _
    ws3     As Worksheet, _
    lst1    As Integer, _
    lst2    As Integer


Set ws1 = Sheets("Sheet1")
Set ws2 = Sheets("Sheet2")
Set ws3 = Sheets("Sheet3")

lst1 = ws1.Cells(65536, "A").End(xlUp).Row
lst2 = ws2.Cells(65536, "A").End(xlUp).Row

ws1.Range("A1:F" & lst1).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=ws2.Range("A1:A" & lst2), _
    CopyToRange:=ws3.Columns("A:F"), Unique:=True
End Sub
Random Solutions  
 
programming4us programming4us