Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Copy Rows Based On Criteria

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...
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Copy Rows Based On Criteria

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
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...

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Copy Rows Based On Criteria

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:D" & 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" wrote in message
...
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...



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Copy Rows Based On Criteria

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
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy and past based on criteria ram Excel Programming 4 October 2nd 09 08:43 PM
How do I find and copy rows based on specific criteria? Georgew New Users to Excel 3 May 29th 09 11:07 AM
Copy rows based on specific criteria Alvin Excel Programming 3 August 11th 08 07:30 PM
Automatically copy rows based on criteria Jay Excel Discussion (Misc queries) 5 November 9th 07 07:55 PM
Help: auto-copy entire rows from 1 sheet (based on cell criteria) to another sheet. bertbarndoor Excel Programming 4 October 5th 07 04:00 PM


All times are GMT +1. The time now is 09:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"