Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default Macro to copy & paste data

I am looking for a macro which copies the data from the selected
range(Dynamic range) and pastes it into a different sheet. I tried recording
a macro and run it,but the range is fixed. The range should be the selected
text and should not be fixed range.
Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,441
Default Macro to copy & paste data

It would help if you posted the macro, but often the solution is to change code like

Range("A2:C10").Copy .....

to

Selection.Copy

HTH,
Bernie
MS Excel MVP


"Satish" wrote in message
...
I am looking for a macro which copies the data from the selected
range(Dynamic range) and pastes it into a different sheet. I tried recording
a macro and run it,but the range is fixed. The range should be the selected
text and should not be fixed range.
Thanks in advance.



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,276
Default Macro to copy & paste data

Hi,
Try this is working for me, change columns as needed

Pick a column between J and O (inclusive) that will have the most information
displayed down the sheet. For this example we'll assume it's column M, plus
this keeps us with a method that works with any of the columns, not just J or
O

Dim lastRow as Long
dim rngAddress as String
dim rngToCopy as Range
lastRow = Range("M" & Rows.Count).End(xlUp).Row
rngAddress = "J10:O" & lastRow


that gives you address of the range and you can use that address to set a
range as:
Set rngToCopy = ActiveWorkbook.Worksheets("SourceSheet").Range(rng Address)

then go from there for your copy/paste into the other workbook and
worksheet. A generic way (change workbook/sheet names as needed) - this does
the same as copy, assuming second workbook is open:
(this would be all one line)

Workbooks("OtherBook.xls").Worksheets("CopySheet") .Range(rngAddress).Value =
rngToCopy.Value

That would copy it into J10:O## in the other book.



"Satish" wrote:

I am looking for a macro which copies the data from the selected
range(Dynamic range) and pastes it into a different sheet. I tried recording
a macro and run it,but the range is fixed. The range should be the selected
text and should not be fixed range.
Thanks in advance.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default Macro to copy & paste data

Thanks Eduardo & Bernie.

"Eduardo" wrote:

Hi,
Try this is working for me, change columns as needed

Pick a column between J and O (inclusive) that will have the most information
displayed down the sheet. For this example we'll assume it's column M, plus
this keeps us with a method that works with any of the columns, not just J or
O

Dim lastRow as Long
dim rngAddress as String
dim rngToCopy as Range
lastRow = Range("M" & Rows.Count).End(xlUp).Row
rngAddress = "J10:O" & lastRow


that gives you address of the range and you can use that address to set a
range as:
Set rngToCopy = ActiveWorkbook.Worksheets("SourceSheet").Range(rng Address)

then go from there for your copy/paste into the other workbook and
worksheet. A generic way (change workbook/sheet names as needed) - this does
the same as copy, assuming second workbook is open:
(this would be all one line)

Workbooks("OtherBook.xls").Worksheets("CopySheet") .Range(rngAddress).Value =
rngToCopy.Value

That would copy it into J10:O## in the other book.



"Satish" wrote:

I am looking for a macro which copies the data from the selected
range(Dynamic range) and pastes it into a different sheet. I tried recording
a macro and run it,but the range is fixed. The range should be the selected
text and should not be fixed range.
Thanks in advance.

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 Macro using large amount of Data Nikki Excel Discussion (Misc queries) 2 December 10th 08 03:12 PM
1 Create a macro to Copy & paste certain data to another sheet Lin1981 Excel Discussion (Misc queries) 1 November 6th 08 11:56 PM
Macro to Copy data from a list in sheet1 and paste into sheet2 Michael Excel Discussion (Misc queries) 3 April 23rd 08 06:52 PM
Macro to Copy/Paste Data into one wksht, skipp one row before past Shoney Excel Discussion (Misc queries) 1 February 22nd 08 01:28 AM
Compare two wk sheets with common data using copy paste macro conejo Excel Worksheet Functions 0 October 8th 07 09:21 AM


All times are GMT +1. The time now is 06:53 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"