Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 163
Default Copying and Pasting Macro from one worksheet to another

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




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Copying and Pasting Macro from one worksheet to another

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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Copying and Pasting Macro from one worksheet to another

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
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
holding worksheet formats when copying/pasting hsyrddy Excel Discussion (Misc queries) 2 November 28th 07 09:59 PM
Copying & Pasting into a newly created worksheet JohnUK Excel Programming 1 October 13th 07 02:10 PM
Copying and Pasting Worksheet between workbooks fbagirov Excel Programming 2 March 16th 07 01:05 PM
Copying and Pasting a Worksheet Jim Pockmire Setting up and Configuration of Excel 1 September 8th 05 02:57 PM
Copying and Pasting in a different worksheet (Urgent) Lolly[_2_] Excel Programming 4 August 24th 04 02:29 PM


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