PC Review


Reply
Thread Tools Rate Thread

Destination:=.Cells(.Rows.Count, "A").End(xlUp).Row + 1

 
 
J.W. Aldridge
Guest
Posts: n/a
 
      6th May 2009
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

 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      6th May 2009
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
>
>

 
Reply With Quote
 
J.W. Aldridge
Guest
Posts: n/a
 
      6th May 2009
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
 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      6th May 2009
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" <(E-Mail Removed)> wrote in message
news:8b441f36-dec1-4cd1-b089-(E-Mail Removed)...
> 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


 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      6th May 2009
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 With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      6th May 2009
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" <(E-Mail Removed)> wrote in message
news:9897ED63-302F-4B23-A343-(E-Mail Removed)...
> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


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 Microsoft Excel Setup 1 30th Jul 2009 02:24 PM
myRow = Cells(Rows.Count, 2).End(xlUp).Row Dave F Microsoft Excel Programming 4 19th Jun 2007 02:30 PM
Re: "Do you want to replace the contents of the destination cells?" Gord Dibben Microsoft Excel Misc 3 16th Jan 2007 12:02 AM
Cells(Rows.Count, "b").End(xlUp).Row Kate Microsoft Excel Programming 1 25th May 2006 04:31 PM
Macro causes "Do you want to replace the contents of the destination cells" JB Microsoft Excel Programming 1 16th Oct 2004 11:25 PM


Features
 

Advertising
 

Newsgroups
 


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