#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default Macro-indirect cell

Hi, i have this code:

Sub copy1()
Dim lastRow As Long
lastRow = Worksheets("Sheet2").Cells(Worksheets("Sheet2").Ro ws.Count,
"A").End(xlUp).Row
Worksheets("Sheet1").UsedRange.Copy
Worksheets("Sheet2").Activate
Range("A" & (lastRow + 1)).Select
ActiveSheet.Paste
End Sub

Can this code be made to copy rows to a specific sheet?
In "M1" i will write october, so when i run macro, the code to copy rows to
"october" sheet. If i write november, then the code to copy rows to
"november" sheet.
Can this be done?
Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Macro-indirect cell

Hi,

Like this

Sub copy1()
Dim lastRow As Long
Dim MySheet As String
MySheet = Sheets("Sheet1").Range("M1").Value
Worksheets("Sheet1").UsedRange.Copy
lastRow = Worksheets("Sheet2").Cells(Worksheets("Sheet2") _
..Rows.Count, "A").End(xlUp).Row
Worksheets(MySheet).Range("A" & (lastRow + 1)).PasteSpecial
End Sub

Mike

"puiuluipui" wrote:

Hi, i have this code:

Sub copy1()
Dim lastRow As Long
lastRow = Worksheets("Sheet2").Cells(Worksheets("Sheet2").Ro ws.Count,
"A").End(xlUp).Row
Worksheets("Sheet1").UsedRange.Copy
Worksheets("Sheet2").Activate
Range("A" & (lastRow + 1)).Select
ActiveSheet.Paste
End Sub

Can this code be made to copy rows to a specific sheet?
In "M1" i will write october, so when i run macro, the code to copy rows to
"october" sheet. If i write november, then the code to copy rows to
"november" sheet.
Can this be done?
Thanks!

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,533
Default Macro-indirect cell

Hi

You can use same technique as in my reply to your last post.

This one-liner code does what you need;

Sub copy1()
Worksheets("Sheet1").UsedRange.Copy Worksheets(Range("M1").Value).Range("A"
& Rows.Count).End(xlUp).Offset(1, 0)
End Sub

Regards,
Per

"puiuluipui" skrev i meddelelsen
...
Hi, i have this code:

Sub copy1()
Dim lastRow As Long
lastRow = Worksheets("Sheet2").Cells(Worksheets("Sheet2").Ro ws.Count,
"A").End(xlUp).Row
Worksheets("Sheet1").UsedRange.Copy
Worksheets("Sheet2").Activate
Range("A" & (lastRow + 1)).Select
ActiveSheet.Paste
End Sub

Can this code be made to copy rows to a specific sheet?
In "M1" i will write october, so when i run macro, the code to copy rows
to
"october" sheet. If i write november, then the code to copy rows to
"november" sheet.
Can this be done?
Thanks!


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,124
Default Macro-indirect cell

You could and should use a data validation dropdown list in cell m1 so you
don't have to type it

Sub copySAS()
Dim LR As Long
With Sheets(Range("m1").Value)
lr = .Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Sheet1").UsedRange.Copy .cells(lr,1)
End With
end sub



--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"puiuluipui" wrote in message
...
Hi, i have this code:

Sub copy1()
Dim lastRow As Long
lastRow = Worksheets("Sheet2").Cells(Worksheets("Sheet2").Ro ws.Count,
"A").End(xlUp).Row
Worksheets("Sheet1").UsedRange.Copy
Worksheets("Sheet2").Activate
Range("A" & (lastRow + 1)).Select
ActiveSheet.Paste
End Sub

Can this code be made to copy rows to a specific sheet?
In "M1" i will write october, so when i run macro, the code to copy rows
to
"october" sheet. If i write november, then the code to copy rows to
"november" sheet.
Can this be done?
Thanks!


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default Macro-indirect cell

Hi, it's working, but the macro replace the content in "october" sheet. I
need to add content.
And another thing is that in macro, is a line with Sheet2 adn if i rename
sheet2, i receive an error. I must have an sheet2 in my workbook? O the code
can be remade so, the sheet2 line to dissapear?
But the real problem is with adding rows instead of replacing.
Can this be done?
Thanks!

"Mike H" wrote:

Hi,

Like this

Sub copy1()
Dim lastRow As Long
Dim MySheet As String
MySheet = Sheets("Sheet1").Range("M1").Value
Worksheets("Sheet1").UsedRange.Copy
lastRow = Worksheets("Sheet2").Cells(Worksheets("Sheet2") _
.Rows.Count, "A").End(xlUp).Row
Worksheets(MySheet).Range("A" & (lastRow + 1)).PasteSpecial
End Sub

Mike

"puiuluipui" wrote:

Hi, i have this code:

Sub copy1()
Dim lastRow As Long
lastRow = Worksheets("Sheet2").Cells(Worksheets("Sheet2").Ro ws.Count,
"A").End(xlUp).Row
Worksheets("Sheet1").UsedRange.Copy
Worksheets("Sheet2").Activate
Range("A" & (lastRow + 1)).Select
ActiveSheet.Paste
End Sub

Can this code be made to copy rows to a specific sheet?
In "M1" i will write october, so when i run macro, the code to copy rows to
"october" sheet. If i write november, then the code to copy rows to
"november" sheet.
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
Allow EXCEL INDIRECT(ADDRESS()) and INDIRECT(RANGE()) functions Mike Barlow Excel Worksheet Functions 7 May 21st 23 07:42 PM
2Q:Indirect worksheet selection in macro, Calc off for specific sh seed Excel Discussion (Misc queries) 1 December 30th 08 09:11 PM
Using INDIRECT in a macro/vba gcouch Excel Discussion (Misc queries) 0 February 26th 08 09:37 PM
Macro that sort on clnm populated by indirect [email protected] Excel Discussion (Misc queries) 2 March 2nd 07 03:45 PM
Using Indirect & Creating a worksheet Macro Bill Healy Excel Worksheet Functions 1 November 5th 04 10:51 AM


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