Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default Macro copy from range

Hi, i need the below code to copy rows but only from A to J.

In M1 i have "Sheet3". The below code is saving rows to "Sheet3". If i write
"Sheet4" to cell "M1", then the code is saving rows to "Sheet4".
The code copy and add rows to the specified sheet. I need the code to do
exactly the same thing, but to copy only from range "A:J"


Sub copy3()
Dim LastRow As Long
Dim MySheet As String
MySheet = Sheets("Sheet1").Range("M1").Value
LastRow = Worksheets(MySheet).Cells(Worksheets(MySheet).Rows .Count,
"A").End(xlUp).Row
Worksheets("Sheet1").UsedRange.Copy
Worksheets(MySheet).Activate
Range("A" & (LastRow + 1)).Select
ActiveSheet.Paste
Worksheets(MySheet).Range("A" & (LastRow + 1)).PasteSpecial
Application.CutCopyMode = False
Sheets("Sheet1").Activate
Range("A1").Select

End Sub

Can this be done?
Thanks!
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default Macro copy from range

I believe that this will do what you want. It could be neater, but since
you're already used to it working the way it does, I left well enough alone.
As always, first test it in a copy of your workbook so that if I got
something wrong, I haven't messed you up too badly.

Sub copy_AtoJ()

Dim LastRow As Long
Dim MySheet As String
MySheet = Sheets("Sheet1").Range("M1").Value
LastRow = worksheets("Sheet1").Range("A" & rows.Count). _
end(xlup).Row
Worksheets("Sheet1").Range("A1:J" & lastrow).Copy
LastRow = Worksheets(MySheet).Cells(Worksheets(MySheet). _
Rows.Count, "A").End(xlUp).Row
Worksheets(MySheet).Activate
Range("A" & (LastRow + 1)).Select
ActiveSheet.Paste
Worksheets(MySheet).Range("A" & (LastRow + 1)).PasteSpecial
Application.CutCopyMode = False
Sheets("Sheet1").Activate
Range("A1").Select

End Sub


"puiuluipui" wrote:

Hi, i need the below code to copy rows but only from A to J.

In M1 i have "Sheet3". The below code is saving rows to "Sheet3". If i write
"Sheet4" to cell "M1", then the code is saving rows to "Sheet4".
The code copy and add rows to the specified sheet. I need the code to do
exactly the same thing, but to copy only from range "A:J"


Sub copy3()
Dim LastRow As Long
Dim MySheet As String
MySheet = Sheets("Sheet1").Range("M1").Value
LastRow = Worksheets(MySheet).Cells(Worksheets(MySheet).Rows .Count,
"A").End(xlUp).Row
Worksheets("Sheet1").UsedRange.Copy
Worksheets(MySheet).Activate
Range("A" & (LastRow + 1)).Select
ActiveSheet.Paste
Worksheets(MySheet).Range("A" & (LastRow + 1)).PasteSpecial
Application.CutCopyMode = False
Sheets("Sheet1").Activate
Range("A1").Select

End Sub

Can this be done?
Thanks!

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default Macro copy from range

It's working great!
Thanks!

"JLatham" wrote:

I believe that this will do what you want. It could be neater, but since
you're already used to it working the way it does, I left well enough alone.
As always, first test it in a copy of your workbook so that if I got
something wrong, I haven't messed you up too badly.

Sub copy_AtoJ()

Dim LastRow As Long
Dim MySheet As String
MySheet = Sheets("Sheet1").Range("M1").Value
LastRow = worksheets("Sheet1").Range("A" & rows.Count). _
end(xlup).Row
Worksheets("Sheet1").Range("A1:J" & lastrow).Copy
LastRow = Worksheets(MySheet).Cells(Worksheets(MySheet). _
Rows.Count, "A").End(xlUp).Row
Worksheets(MySheet).Activate
Range("A" & (LastRow + 1)).Select
ActiveSheet.Paste
Worksheets(MySheet).Range("A" & (LastRow + 1)).PasteSpecial
Application.CutCopyMode = False
Sheets("Sheet1").Activate
Range("A1").Select

End Sub


"puiuluipui" wrote:

Hi, i need the below code to copy rows but only from A to J.

In M1 i have "Sheet3". The below code is saving rows to "Sheet3". If i write
"Sheet4" to cell "M1", then the code is saving rows to "Sheet4".
The code copy and add rows to the specified sheet. I need the code to do
exactly the same thing, but to copy only from range "A:J"


Sub copy3()
Dim LastRow As Long
Dim MySheet As String
MySheet = Sheets("Sheet1").Range("M1").Value
LastRow = Worksheets(MySheet).Cells(Worksheets(MySheet).Rows .Count,
"A").End(xlUp).Row
Worksheets("Sheet1").UsedRange.Copy
Worksheets(MySheet).Activate
Range("A" & (LastRow + 1)).Select
ActiveSheet.Paste
Worksheets(MySheet).Range("A" & (LastRow + 1)).PasteSpecial
Application.CutCopyMode = False
Sheets("Sheet1").Activate
Range("A1").Select

End Sub

Can this be done?
Thanks!

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
macro to copy only range with data ramzi Excel Discussion (Misc queries) 2 January 29th 09 11:28 AM
macro to copy range Frank Situmorang[_2_] Excel Worksheet Functions 7 June 3rd 08 09:54 AM
Need help - Macro to copy a specific range Dileep Chandran Excel Worksheet Functions 9 December 5th 06 09:10 AM
Need help - Macro to copy a specific range Dileep Chandran Excel Worksheet Functions 0 December 4th 06 10:24 AM
MACRO TO COPY TO A RANGE asuncionw Excel Discussion (Misc queries) 3 February 9th 06 04:39 PM


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