PC Review


Reply
Thread Tools Rate Thread

Copy Rows Based On Criteria

 
 
Sean
Guest
Posts: n/a
 
      23rd Mar 2010
I have a workbook where I have thousands of rows of data. I want to
automatically extract the entire row if column "D" has an "X" in it, to a new
workbook. Is this possible??? Any help would be great...
 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      23rd Mar 2010
Try some code like the following:

Sub AAA()
Dim R As Range
Dim Dest As Range
Dim WB As Workbook
Dim WS As Worksheet
Dim LastRow As Long

Set WS = ActiveSheet
With WS
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With

Set WB = Workbooks.Add
Set Dest = WB.Worksheets(1).Range("A1")

Set R = WS.Range("A1")
Do Until R.Row < LastRow
If R.EntireRow.Cells(1, "D").Value = "X" Then
R.EntireRow.Copy Destination:=Dest
Set Dest = Dest(2, 1)
End If
Set R = R(2, 1)
Loop
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com




On Tue, 23 Mar 2010 13:54:01 -0700, Sean
<(E-Mail Removed)> wrote:

>I have a workbook where I have thousands of rows of data. I want to
>automatically extract the entire row if column "D" has an "X" in it, to a new
>workbook. Is this possible??? Any help would be great...

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      23rd Mar 2010
The code below will check column D of the ActiveSheet in the Workbook
containing the code. It will copy any row that has an X in column D and put
it into sheet1 of a new workbook which is created by the macro. You will
need to modify the path and file name on the SaveAs line to suit your
specific needs.

Sub cpyX()
Dim lr As Long, rng As Range, sh As Worksheet
Dim nWB As Workbook, sh2 As Worksheet, lr2 As Long
Set sh = ThisWorkbook.ActiveSheet
lr = sh.Cells(Rows.Count, 4).End(xlUp).Row
Set rng = Range("D2" & lr)
Set nWB = Workbooks.Add
ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\myWb.xls"
Set sh2 = nWB.Sheets(1)
For Each c In rng
If UCase(c) = "X" Then
lr2 = sh2.Cells(Rows.Count, 1).End(xlUp).Row
c.EntireRow.Copy sh2.Range("A" & lr2 + 1)
End If
Next
End Sub




"Sean" <(E-Mail Removed)> wrote in message
news:3778499C-9BE2-48B1-AA99-(E-Mail Removed)...
>I have a workbook where I have thousands of rows of data. I want to
> automatically extract the entire row if column "D" has an "X" in it, to a
> new
> workbook. Is this possible??? Any help would be great...



 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      23rd Mar 2010
Possible, yes.

Do you want a new workbook for every row with an "X"?

See Ron de Bruin's site for code and methods.

http://www.rondebruin.nl/copy5.htm


Gord Dibben MS Excel MVP

On Tue, 23 Mar 2010 13:54:01 -0700, Sean <(E-Mail Removed)>
wrote:

>I have a workbook where I have thousands of rows of data. I want to
>automatically extract the entire row if column "D" has an "X" in it, to a new
>workbook. Is this possible??? Any help would be great...


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I find and copy rows based on specific criteria? Georgew Microsoft Excel New Users 3 29th May 2009 11:07 AM
Copy rows based on specific criteria Alvin Microsoft Excel Programming 3 11th Aug 2008 07:30 PM
Automatically copy rows based on criteria =?Utf-8?B?SmF5?= Microsoft Excel Misc 5 9th Nov 2007 07:55 PM
Help: auto-copy entire rows from 1 sheet (based on cell criteria) to another sheet. bertbarndoor Microsoft Excel Programming 4 5th Oct 2007 04:00 PM
SUM rows based on criteria Annabelle Microsoft Excel Worksheet Functions 8 20th Nov 2003 02:42 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:23 AM.