PC Review


Reply
Thread Tools Rate Thread

Copying and Pasting Macro from one worksheet to another

 
 
Neil Holden
Guest
Posts: n/a
 
      27th Jul 2009
Please help, we have created the following code that should copy a entire row
from the active worksheet, open an existing workbook and paste the copied
data into the next available row. However it is currently pasting it into
the next available row of the original workbook. Below you will find my
current code: Am I doing somthing stupid!!! Much appreciated.

Sub CopyLast()

Sheets("Summary").Range("A2").EntireRow.Copy

Application.ScreenUpdating = False

Workbooks.Open "C:\Documents and
Settings\david.cope\Desktop\CHR\Calcs.xls", UpdateLinks:=1

Windows("Calcs.xls").Activate

With Worksheets("Sheet1")

Dim NextRow As Range

Set NextRow = Sheet1.Cells(Cells.Rows.Count, 1).End(xlUp).Offset(1, 0)

NextRow.PasteSpecial (xlValues)

Application.CutCopyMode = False

Application.ScreenUpdating = True

End With

End Sub




 
Reply With Quote
 
 
 
 
Barb Reinhardt
Guest
Posts: n/a
 
      27th Jul 2009
Try this

Option Explicit

Sub CopyLast()
Dim aWB As Excel.Workbook
Dim aWS As Excel.Worksheet
Dim myWB As Excel.Workbook
Dim myWS As Excel.Worksheet

Set aWB = ActiveWorkbook
Set aWS = aWB.Sheets("Summary")

aWS.Range("A2").EntireRow.Copy

Application.ScreenUpdating = False

Set myWB = Workbooks.Open _
("C:\Documents and Settings\david.cope\Desktop\CHR\Calcs.xls", _
UpdateLinks:=1)

'Windows("Calcs.xls").Activate

Set myWS = myWB.Worksheets("Sheet1")

'With Worksheets("Sheet1")

Dim NextRow As Range

Set NextRow = myWS.Cells(Cells.Rows.Count, 1).End(xlUp).Offset(1, 0)

NextRow.PasteSpecial (xlValues)

Application.CutCopyMode = False

Application.ScreenUpdating = True

'End With

End Sub

HTH,
Barb Reinhardt

"Neil Holden" wrote:

> Please help, we have created the following code that should copy a entire row
> from the active worksheet, open an existing workbook and paste the copied
> data into the next available row. However it is currently pasting it into
> the next available row of the original workbook. Below you will find my
> current code: Am I doing somthing stupid!!! Much appreciated.
>
> Sub CopyLast()
>
> Sheets("Summary").Range("A2").EntireRow.Copy
>
> Application.ScreenUpdating = False
>
> Workbooks.Open "C:\Documents and
> Settings\david.cope\Desktop\CHR\Calcs.xls", UpdateLinks:=1
>
> Windows("Calcs.xls").Activate
>
> With Worksheets("Sheet1")
>
> Dim NextRow As Range
>
> Set NextRow = Sheet1.Cells(Cells.Rows.Count, 1).End(xlUp).Offset(1, 0)
>
> NextRow.PasteSpecial (xlValues)
>
> Application.CutCopyMode = False
>
> Application.ScreenUpdating = True
>
> End With
>
> End Sub
>
>
>
>

 
Reply With Quote
 
Barb Reinhardt
Guest
Posts: n/a
 
      27th Jul 2009
FWIW, when you used this line

Set NextRow = Sheet1.Cells(Cells.Rows.Count, 1).End(xlUp).Offset(1, 0)

It used Sheet1 of the workbook with the code.

"Neil Holden" wrote:

> Please help, we have created the following code that should copy a entire row
> from the active worksheet, open an existing workbook and paste the copied
> data into the next available row. However it is currently pasting it into
> the next available row of the original workbook. Below you will find my
> current code: Am I doing somthing stupid!!! Much appreciated.
>
> Sub CopyLast()
>
> Sheets("Summary").Range("A2").EntireRow.Copy
>
> Application.ScreenUpdating = False
>
> Workbooks.Open "C:\Documents and
> Settings\david.cope\Desktop\CHR\Calcs.xls", UpdateLinks:=1
>
> Windows("Calcs.xls").Activate
>
> With Worksheets("Sheet1")
>
> Dim NextRow As Range
>
> Set NextRow = Sheet1.Cells(Cells.Rows.Count, 1).End(xlUp).Offset(1, 0)
>
> NextRow.PasteSpecial (xlValues)
>
> Application.CutCopyMode = False
>
> Application.ScreenUpdating = True
>
> End With
>
> End Sub
>
>
>
>

 
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
Copying and Pasting Worksheet between workbooks =?Utf-8?B?ZmJhZ2lyb3Y=?= Microsoft Excel Programming 2 16th Mar 2007 01:05 PM
Copying and Pasting a Worksheet Jim Pockmire Microsoft Excel Setup 1 8th Sep 2005 02:57 PM
Copying worksheet and pasting on new worksheet, it makes page bre =?Utf-8?B?ZXhjZWwgcXVlc3Rpb24=?= Microsoft Excel Worksheet Functions 2 24th Oct 2004 12:41 AM
Copying and Pasting in a different worksheet (Urgent) =?Utf-8?B?TG9sbHk=?= Microsoft Excel Programming 4 24th Aug 2004 02:29 PM
Re: protecting worksheet from copying and pasting Charlie Microsoft Excel Worksheet Functions 0 4th Jun 2004 09:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:11 PM.