Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
ML ML is offline
external usenet poster
 
Posts: 57
Default Macro to copy nonadjacent range and paste

The macro aims to select whatever in column A and whatever in column C, then
copy and paste to a new workbook as column A and B. Since the number of rows
in column A and C are uncertain, I have to use End Down to select the cells.
However, the marco below only copy and paste column A but not C. What's
wrong?

Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range("A1:A5,C1").Select
Range("C1").Activate
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Macro to copy nonadjacent range and paste

Since your pasting to a new worksheet in a new workbook, couldn't you just
bypass the last cell stuff and just copy|paste the entire column.

Dim DestWks as worksheet
dim ActWks as worksheet

set actwks = activesheet

'add a new single sheet workbook and use that sheet
set destwks = workbooks.add(1).worksheets(1)

actwks.range("A1").entirecolumn.copy _
destination:=destwks.range("A1")

actwks.range("C1").entirecolumn.copy _
destination:=destwks.range("b1")


=======
But if you wanted, you could do something like:

Dim DestWks as worksheet
dim ActWks as worksheet
dim RngToCopy as range

set actwks = activesheet

'add a new single sheet workbook and use that sheet
set destwks = workbooks.add(1).worksheets(1)

with actwks
set rngtocopy = .range("a1",.cells(.rows.count,"A").end(xlup)
end with

rngtocopy.copy _
destination:=destwks.range("A1")

with actwks
set rngtocopy = .range("c1",.cells(.rows.count,"c").end(xlup)
end with

rngtocopy.copy _
destination:=destwks.range("b1")



ML wrote:

The macro aims to select whatever in column A and whatever in column C, then
copy and paste to a new workbook as column A and B. Since the number of rows
in column A and C are uncertain, I have to use End Down to select the cells.
However, the marco below only copy and paste column A but not C. What's
wrong?

Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range("A1:A5,C1").Select
Range("C1").Activate
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste


--

Dave Peterson
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, Paste and Rename a Range using a macro [email protected] Excel Discussion (Misc queries) 1 April 15th 08 03:58 PM
Macro - copy a range and paste it in a new sheet 12 times Eva Excel Worksheet Functions 0 September 26th 07 07:20 PM
macro to copy/paste range for printing Mike Wasilewski Excel Programming 8 April 14th 06 07:53 PM
Macro to copy, paste in a range and then delete Garry Excel Discussion (Misc queries) 0 March 23rd 06 07:37 PM
Macro to copy range of cells and paste into 1 sheet Dean[_9_] Excel Programming 2 February 20th 06 12:53 AM


All times are GMT +1. The time now is 03:04 AM.

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"