Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default Destination:=.Cells(.Rows.Count, "A").End(xlUp).Row + 1

Need to duplicate code but change destination.


' THIS WORKS
With Worksheets("Ind Templates")
.Range("A1:f13").Copy _
Destination:=Sh.Range("a1")

End With

I need destination to be the row below the last row used in A.
I tried this, but didnt work.
Destination:=.Cells(.Rows.Count, "A").End(xlUp).Row + 1

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Destination:=.Cells(.Rows.Count, "A").End(xlUp).Row + 1

Try this

Dim lngLastRow As Long

With Worksheets("Ind Templates")
lngLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
..Range("A1:f13").Copy Destination:=.Range("a" & lngLastRow)
End With


If this post helps click Yes
---------------
Jacob Skaria


"J.W. Aldridge" wrote:

Need to duplicate code but change destination.


' THIS WORKS
With Worksheets("Ind Templates")
.Range("A1:f13").Copy _
Destination:=Sh.Range("a1")

End With

I need destination to be the row below the last row used in A.
I tried this, but didnt work.
Destination:=.Cells(.Rows.Count, "A").End(xlUp).Row + 1


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default Destination:=.Cells(.Rows.Count, "A").End(xlUp).Row + 1

Mr. Jacob,

unfortunately, this didn't work.
Let me give you the full code that i am using...


Private Sub Workbook_newsheet(ByVal Sh As Object)
Dim LastRow As Long

With Worksheets("Ind Templates")
.Range("A1:f13").Copy _
Destination:=Sh.Range("a1")

With Worksheets("Ind Templates")
lngLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
..Range("A39:f50").Copy Destination:=.Range("a" & lngLastRow)

End With

End With

End Sub
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Destination:=.Cells(.Rows.Count, "A").End(xlUp).Row + 1

I think your code is mixing sheet references. See if this does what you
want...

Private Sub Workbook_NewSheet(ByVal Sh As Object)
Dim lngLastRow As Long
With Worksheets("Ind Templates")
.Range("A1:F13").Copy Destination:=Sh.Range("a1")
lngLastRow = Sh.Cells(Sh.Rows.Count, "A").End(xlUp).Row + 1
.Range("A39:F50").Copy Destination:=Sh.Range("A" & lngLastRow)
End With
End Sub

--
Rick (MVP - Excel)


"J.W. Aldridge" wrote in message
...
Mr. Jacob,

unfortunately, this didn't work.
Let me give you the full code that i am using...


Private Sub Workbook_newsheet(ByVal Sh As Object)
Dim LastRow As Long

With Worksheets("Ind Templates")
.Range("A1:f13").Copy _
Destination:=Sh.Range("a1")

With Worksheets("Ind Templates")
lngLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
.Range("A39:f50").Copy Destination:=.Range("a" & lngLastRow)

End With

End With

End Sub


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Destination:=.Cells(.Rows.Count, "A").End(xlUp).Row + 1

Just another option and in explanation to the OP. If using With then all
references preceded by the dot refer to the With. If referring to another
sheet for the Destination then its specific reference must be included.

With Worksheets("Ind Templates")
.Range("A1:F13").Copy _
Destination:= _
sh.Cells(sh.Rows.Count, "A").End(xlUp).Offset(1, 0)
End With

--
Regards,

OssieMac




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Destination:=.Cells(.Rows.Count, "A").End(xlUp).Row + 1

Good point about using the cell reference from the last cell calculation
directly. However, I think there are two separate range copies being
performed with the second one dependent on the first. I think this is what
it should be...

Private Sub Workbook_NewSheet(ByVal Sh As Object)
With Worksheets("Ind Templates")
.Range("A1:F13").Copy Destination:=Sh.Range("A1")
.Range("A39:F50").Copy Destination:=Sh.Cells( _
Sh.Rows.Count, "A").End(xlUp).Offset(1)
End With
End Sub

--
Rick (MVP - Excel)


"OssieMac" wrote in message
...
Just another option and in explanation to the OP. If using With then all
references preceded by the dot refer to the With. If referring to another
sheet for the Destination then its specific reference must be included.

With Worksheets("Ind Templates")
.Range("A1:F13").Copy _
Destination:= _
sh.Cells(sh.Rows.Count, "A").End(xlUp).Offset(1, 0)
End With

--
Regards,

OssieMac



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
How do I suppress the "Do you want to overwrite the destination cells" message Rojo Habe Setting up and Configuration of Excel 1 July 30th 09 02:24 PM
Multiple "source" workbooks linked to single "destination" workboo DAVEJAY Excel Worksheet Functions 1 September 17th 07 05:33 PM
myRow = Cells(Rows.Count, 2).End(xlUp).Row Dave F[_2_] Excel Programming 4 June 19th 07 02:30 PM
Cells(Rows.Count, "b").End(xlUp).Row Kate[_2_] Excel Programming 1 May 25th 06 04:31 PM
Macro causes "Do you want to replace the contents of the destination cells" JB[_2_] Excel Programming 1 October 16th 04 11:25 PM


All times are GMT +1. The time now is 01:55 PM.

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

About Us

"It's about Microsoft Excel"