Check the value and return the result

Closed
saran - Sep 14, 2009 at 04:33 AM
venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 - Sep 14, 2009 at 09:15 PM
Hello,
Please help me out.

I have followig values in "Sheet1",
Eg:
A
1 Apple
2 Orange
3 Lemon

In "Sheet2",Payments are made for those values present in "Sheet1" and for others.
Eg:
A B
1 Apple $20
2 Tiger $50
3 Lemon $14
4 Apple $36
5 Giraf $54

If value present in "Sheet1" matches in "Sheet2", then the entire row should be retrieved and displayed in "Sheet3". Others should be ignored.

Eg:
A B
1 Apple $20
2 Lemon $14
3 Apple $36

Thanks !

1 response

venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 811
Sep 14, 2009 at 09:15 PM
try

Sub test()
Dim rng As Range, c As Range, x As String, cfind As Range
With Worksheets("sheet2")
Set rng = Range(.Range("A1"), .Range("A1").End(xlDown))
For Each c In rng
x = c.Value
Set cfind = Worksheets("sheet1").UsedRange.Cells.Find _
    (what:=x, lookat:=xlWhole)
If Not cfind Is Nothing Then
c.EntireRow.Copy
With Worksheets("sheet3")
.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial
End With
End If
Next c
End With
Application.CutCopyMode = False
End Sub
0