Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Copy and paste between sheets error

I am having a little problem with this code. It won't copy and paste
from one worksheet to another. I have used the same code for copy and
paste before but never in a find loop so I'm guessing maybe I have to
do something different. I also tried

Workbooks("Book1.xls").Worksheets(2).Range(Cells(y , 1), Cells(y,
2)).PasteSpecial Paste:=xlPasteAll

Worksheets(2).Range(Cells(y, 1), Cells(y, 2)).PasteSpecial
Paste:=xlPasteAll

Worksheets("SatLog").Range(Cells(y, 1), Cells(y, 2)).PasteSpecial
Paste:=xlPasteAll

None worked

With Worksheets(1).Range("A1:A500")
Set c = .Find("Substrate # 1", LookIn:=xlValues)

If Not c Is Nothing Then
firstAddress = c.Address
y = 1
Do

Range(c.Offset(0, 0), c.Offset(3, 1)).Copy
Workbooks("Book1.xls").Worksheets("SatLog").Range( Cells(y,
1), Cells(y, 2)).PasteSpecial Paste:=xlPasteAll <--------Errors here
Set c = .FindNext(c)
y = y + 4

Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Copy and paste between sheets error

If SatLog in book1.xls isn't the activesheet, then this line will fail.

Workbooks("Book1.xls").Worksheets("SatLog").Range( Cells(y, 1), _
Cells(y, 2)).PasteSpecial Paste:=xlPasteAll

Those cells() reference refer to the activesheet (if the code is in a general
module) or the worksheet that owns the code (if the code is behind a worksheet).

I'd use something like this (untested):


Dim DestCell as range 'in your declaration section (at the top)

With Worksheets(1).Range("A1:A500")
Set c = .Find("Substrate # 1", LookIn:=xlValues)

If Not c Is Nothing Then
firstAddress = c.Address
y = 1
Do

with workbooks("book1.xls").worksheets("satlog")
set destcell = .range(.cells(y,1),.cells(y,2))
end with

Range(c.Offset(0, 0), c.Offset(3, 1)).Copy
destcell.PasteSpecial Paste:=xlPasteAll

Set c = .FindNext(c)
y = y + 4

Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With





wrote:

I am having a little problem with this code. It won't copy and paste
from one worksheet to another. I have used the same code for copy and
paste before but never in a find loop so I'm guessing maybe I have to
do something different. I also tried

Workbooks("Book1.xls").Worksheets(2).Range(Cells(y , 1), Cells(y,
2)).PasteSpecial Paste:=xlPasteAll

Worksheets(2).Range(Cells(y, 1), Cells(y, 2)).PasteSpecial
Paste:=xlPasteAll

Worksheets("SatLog").Range(Cells(y, 1), Cells(y, 2)).PasteSpecial
Paste:=xlPasteAll

None worked

With Worksheets(1).Range("A1:A500")
Set c = .Find("Substrate # 1", LookIn:=xlValues)

If Not c Is Nothing Then
firstAddress = c.Address
y = 1
Do

Range(c.Offset(0, 0), c.Offset(3, 1)).Copy
Workbooks("Book1.xls").Worksheets("SatLog").Range( Cells(y,
1), Cells(y, 2)).PasteSpecial Paste:=xlPasteAll <--------Errors here
Set c = .FindNext(c)
y = y + 4

Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Copy and paste between sheets error

On Jul 16, 7:55 am, Dave Peterson wrote:
If SatLog in book1.xls isn't the activesheet, then this line will fail.

Workbooks("Book1.xls").Worksheets("SatLog").Range( Cells(y, 1), _
Cells(y, 2)).PasteSpecial Paste:=xlPasteAll

Those cells() reference refer to the activesheet (if the code is in a general
module) or the worksheet that owns the code (if the code is behind a worksheet).

I'd use something like this (untested):

Dim DestCell as range 'in your declaration section (at the top)

With Worksheets(1).Range("A1:A500")
Set c = .Find("Substrate # 1", LookIn:=xlValues)

If Not c Is Nothing Then
firstAddress = c.Address
y = 1
Do

with workbooks("book1.xls").worksheets("satlog")
set destcell = .range(.cells(y,1),.cells(y,2))
end with

Range(c.Offset(0, 0), c.Offset(3, 1)).Copy
destcell.PasteSpecial Paste:=xlPasteAll

Set c = .FindNext(c)
y = y + 4

Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With





wrote:

I am having a little problem with this code. It won't copy and paste
from one worksheet to another. I have used the same code for copy and
paste before but never in a find loop so I'm guessing maybe I have to
do something different. I also tried


Workbooks("Book1.xls").Worksheets(2).Range(Cells(y , 1), Cells(y,
2)).PasteSpecial Paste:=xlPasteAll


Worksheets(2).Range(Cells(y, 1), Cells(y, 2)).PasteSpecial
Paste:=xlPasteAll


Worksheets("SatLog").Range(Cells(y, 1), Cells(y, 2)).PasteSpecial
Paste:=xlPasteAll


None worked


With Worksheets(1).Range("A1:A500")
Set c = .Find("Substrate # 1", LookIn:=xlValues)


If Not c Is Nothing Then
firstAddress = c.Address
y = 1
Do


Range(c.Offset(0, 0), c.Offset(3, 1)).Copy
Workbooks("Book1.xls").Worksheets("SatLog").Range( Cells(y,
1), Cells(y, 2)).PasteSpecial Paste:=xlPasteAll <--------Errors here
Set c = .FindNext(c)
y = y + 4


Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With


--

Dave Peterson- Hide quoted text -

- Show quoted text -


Dave Thank you it did work. SatLog was not the active sheet but the
change you made to the code made it work out. Thanks again.

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
Copy&paste of several sheets Lorenz Excel Programming 3 May 31st 07 05:09 PM
Copy&paste of several sheets Lorenz Excel Discussion (Misc queries) 1 May 29th 07 10:08 PM
Copy-Paste sheets - error in the dates Aninha Excel Worksheet Functions 1 February 28th 06 04:04 PM
Copy and paste between sheets dmg[_2_] Excel Programming 5 November 1st 05 12:56 PM
Code Error - Run Time Error 5 (Disable Cut, Copy & Paste) Tim[_36_] Excel Programming 4 April 23rd 04 02:53 AM


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