Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default copy rows conditionally

Hi,
The below code, which copies a region from Sheet1 to Sheet4 works with no
trouble at all...
But I need to modify it so that only the rows having an "X" on column A will
be copied.

Can anyone suggest an alteration?

'-------------------------
Sub Macro3()
' Macro3 Macro
Sheets("Sheet1").Activate
Range("A5:F400").Select
Selection.Copy
Range("A1").Select

Sheets("Sheet4").Activate
ActiveSheet.Paste
Application.CutCopyMode = False
Range("A1:F400").Select

Selection.Sort Key1:=Range("A2"), Order1:=xlDescending, Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Range("A1").Select
End Sub
'----------------------------
TIA
J_J


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 252
Default copy rows conditionally

This can all be done without SELECTING cells or ranges which slows things down.
Also if you filter the source list on col A before copying, you will only
copy the rows which have an x in col A. So this works for me;

Sub CopyFilteredList()

Dim Source As Range
Dim Dest As Range

Set Source = Sheets("Sheet1").Range("A5:F400")
Set Dest = Sheets("Sheet4").Range("A1")

Source.AutoFilter Field:=1, Criteria1:="x"
Source.Copy Dest 'copy to destination
Application.Goto Dest
Dest.CurrentRegion.Sort Key1:=Range("B1"), Order1:=xlDescending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
'reset source to show all records
Source.AutoFilter

End Sub

"J_J" wrote:

Hi,
The below code, which copies a region from Sheet1 to Sheet4 works with no
trouble at all...
But I need to modify it so that only the rows having an "X" on column A will
be copied.

Can anyone suggest an alteration?

'-------------------------
Sub Macro3()
' Macro3 Macro
Sheets("Sheet1").Activate
Range("A5:F400").Select
Selection.Copy
Range("A1").Select

Sheets("Sheet4").Activate
ActiveSheet.Paste
Application.CutCopyMode = False
Range("A1:F400").Select

Selection.Sort Key1:=Range("A2"), Order1:=xlDescending, Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Range("A1").Select
End Sub
'----------------------------
TIA
J_J



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default copy rows conditionally

It workes here too...thank you gocush.
J_J

"gocush" /delete wrote in message
...
This can all be done without SELECTING cells or ranges which slows things
down.
Also if you filter the source list on col A before copying, you will only
copy the rows which have an x in col A. So this works for me;

Sub CopyFilteredList()

Dim Source As Range
Dim Dest As Range

Set Source = Sheets("Sheet1").Range("A5:F400")
Set Dest = Sheets("Sheet4").Range("A1")

Source.AutoFilter Field:=1, Criteria1:="x"
Source.Copy Dest 'copy to destination
Application.Goto Dest
Dest.CurrentRegion.Sort Key1:=Range("B1"), Order1:=xlDescending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
'reset source to show all records
Source.AutoFilter

End Sub

"J_J" wrote:

Hi,
The below code, which copies a region from Sheet1 to Sheet4 works with no
trouble at all...
But I need to modify it so that only the rows having an "X" on column A
will
be copied.

Can anyone suggest an alteration?

'-------------------------
Sub Macro3()
' Macro3 Macro
Sheets("Sheet1").Activate
Range("A5:F400").Select
Selection.Copy
Range("A1").Select

Sheets("Sheet4").Activate
ActiveSheet.Paste
Application.CutCopyMode = False
Range("A1:F400").Select

Selection.Sort Key1:=Range("A2"), Order1:=xlDescending,
Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Range("A1").Select
End Sub
'----------------------------
TIA
J_J





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
summing across worksheets conditionally and being able to copy for Celia Excel Discussion (Misc queries) 4 March 19th 10 06:37 AM
How do I conditionally format a row and copy the formatting to tab nandu1256 Excel Worksheet Functions 1 March 5th 10 04:15 AM
How can I have Excel conditionally copy a cell CA_stateworker Excel Worksheet Functions 2 September 10th 09 06:23 PM
Conditionally formatting rows junoon Excel Worksheet Functions 4 May 29th 06 10:36 PM
Hiding Rows Conditionally Mike Hogan Excel Discussion (Misc queries) 2 December 9th 04 10:05 PM


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

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

About Us

"It's about Microsoft Excel"