Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default Copy rows to another sheet

Hello. I have a worksheet with several thousand rows. In column F I
have an indicator column (Y or N). Is there a way to have vba scan
the entire sheet, find all rows that have a Y in column F, and copy
that row into the sheet named "Approved" beginning in row 3? And
every time the code is run, clear from row 3 down on the Approved
sheet and rewrite?

Thank you!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 621
Default Copy rows to another sheet

Turn on the macro recorder while you use autofilter to find rows with Y in
column F.

Copy the resultant rows and paste to A3 in "Approved" sheet.

You could also record while clearing old data from "Approved".

Combine the two to clear "Approved" then filter and copy from source sheet.


Gord Dibben MS Excel MVP

On Fri, 29 Apr 2011 10:45:59 -0700 (PDT), Steve
wrote:

Hello. I have a worksheet with several thousand rows. In column F I
have an indicator column (Y or N). Is there a way to have vba scan
the entire sheet, find all rows that have a Y in column F, and copy
that row into the sheet named "Approved" beginning in row 3? And
every time the code is run, clear from row 3 down on the Approved
sheet and rewrite?

Thank you!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Copy rows to another sheet


try this

Sub kTest()

Dim ka, k(), i As Long, n As Long, c As Long, j As Long
Dim wks1 As Worksheet, UB1 As Long, UB2 As Long
Dim wks2 As Worksheet

Set wks1 = Sheets("Sheet1") 'adjust to suit
Set wks2 = Sheets("Approved")

ka = wks1.UsedRange
On Error Resume Next
c = Evaluate("countif(" & wks1.UsedRange.Columns(6).Address &
",""Y"")")
On Error GoTo 0
If c Then
UB1 = UBound(ka, 1)
UB2 = UBound(ka, 2)
ReDim k(1 To c, 1 To UB2)

For i = 1 To UB1
If LCase$(ka(i, 6)) = "y" Then
n = n + 1
For j = 1 To UB2
k(n, j) = ka(i, j)
Next
End If
Next
With wks2.Range("a3")
.Range(.Cells(1), .SpecialCells(11)).ClearContents
.Resize(n, UB2).Value = k
End With
End If

End Sub

Kris

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Copy rows to another sheet

Steve formulated the question :
Hello. I have a worksheet with several thousand rows. In column F I
have an indicator column (Y or N). Is there a way to have vba scan
the entire sheet, find all rows that have a Y in column F, and copy
that row into the sheet named "Approved" beginning in row 3? And
every time the code is run, clear from row 3 down on the Approved
sheet and rewrite?

Thank you!


Try...

Dim wksSource As Worksheet, wksTarget As Worksheet

Set wksSource = ActiveSheet: Set wksTarget = Sheets("Approved")
Application.ScreenUpdating = False
With wksTarget
.Rows("3:" & CStr(.UsedRange.Rows.Count)).ClearContents
End With
With wksSource
.Columns("F:F").AutoFilter Field:=1, Criteria1:="Y"
.UsedRange.Copy wksTarget.Rows("3:3")
.Columns("F:F").AutoFilter
End With
Application.ScreenUpdating = True
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Copy rows to another sheet

Oops! Missed copying of 1st line...


Sub Test_CopyData1()
Dim wksSource As Worksheet, wksTarget As Worksheet

Set wksSource = ActiveSheet: Set wksTarget = Sheets("Approved")
Application.ScreenUpdating = False
With wksTarget
.Rows("3:" & CStr(.UsedRange.Rows.Count)).ClearContents
End With
With wksSource
.Columns("F:F").AutoFilter Field:=1, Criteria1:="Y"
.UsedRange.Copy wksTarget.Rows("3:3")
.Columns("F:F").AutoFilter
End With
Application.ScreenUpdating = True
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default Copy rows to another sheet

Thanks Garry!

On May 1, 10:34*am, GS wrote:
Oops! Missed copying of 1st line...

Sub Test_CopyData1()
* Dim wksSource As Worksheet, wksTarget As Worksheet

* Set wksSource = ActiveSheet: Set wksTarget = Sheets("Approved")
* Application.ScreenUpdating = False
* With wksTarget
* * .Rows("3:" & CStr(.UsedRange.Rows.Count)).ClearContents
* End With
* With wksSource
* * .Columns("F:F").AutoFilter Field:=1, Criteria1:="Y"
* * .UsedRange.Copy wksTarget.Rows("3:3")
* * .Columns("F:F").AutoFilter
* End With
* Application.ScreenUpdating = True
End Sub

--
Garry

Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Copy rows to another sheet

You're welcome, Steve!

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


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 rows from one Data sheet to another sheet based on cell conte John McKeon Excel Discussion (Misc queries) 2 May 15th 10 06:49 AM
copy rows to other sheet Carpe Diem Excel Worksheet Functions 3 December 17th 07 06:58 PM
Copy rows onto existing sheet / start a new sheet if full mg_sv_r Excel Programming 0 November 29th 07 12:57 PM
Search for rows in one sheet and copy into another sheet based on customer id [email protected] Excel Worksheet Functions 1 October 22nd 07 03:09 AM
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 10:23 AM.

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"