View Single Post
  #2  
Old 07-04-2009, 04:27 PM
stanleydgromjr stanleydgromjr is offline
Valued Forum Contributor
 
Join Date: 10 Oct 2008
Location: Northeast Pennsylvania, USA
MS Office Version:Excel 2003, 2007.
Posts: 689
stanleydgromjr has an addiction to Excel
Re: Return Rows whose cell satisy a condition from other Work Sheet

antrix,

Welcome to the Excel Forum.

I am assuming that "Name" is in cell A1, in Sheet1, and we are copying to Sheet2 (with the same titles in row 1).


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Adding the Macro
1. Copy the below macro, by highlighting the macro code and pressing the keys CTRL+C
2. Open your workbook
3. Press the keys ALT+F11 to open the Visual Basic Editor
4. Press the keys ALT+I to activate the Insert menu
5. Press M to insert a Standard Module
6. Paste the code by pressing the keys CTRL+V
7. Press the keys ALT+Q to exit the Editor, and return to Excel.

Code:
Option Explicit
Sub FindMatches()
Dim c As Range, firstaddress As String
Application.ScreenUpdating = False
With Sheets("Sheet1")
  With .Columns(3)
    Set c = .Find(1, LookIn:=xlValues, LookAt:=xlWhole)
    If Not c Is Nothing Then
      firstaddress = c.Address
      Do
        c.EntireRow.Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
        Set c = .FindNext(c)
      Loop While Not c Is Nothing And c.Address <> firstaddress
    End If
  End With
End With
Application.ScreenUpdating = True
End Sub

Then run the "FindMatches" macro.
__________________
Have a great day,
Stan

stanleydgromjr
Windows Vista Business, Excel 2003 and 2007
Reply With Quote