Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default PasteSpecial method for range class failed

Hello Gurus,

Attached is a code snippet where I get an error for copying and pasting. I
am trying to open different workbooks and copy certain data and paste it into
a single workbook. however for the first workbook I dont get an error in
pasting values, but for the second workbook excel does copy the values but
cannot paste it. Is there something I am missing in the code.

thank you in advance

For count = LBound(ID) To UBound(ID)
Set qWb = Workbooks.Open(FileName:=workingDir &
Application.PathSeparator & ncases(ID(count)), UpdateLinks:=False)
qWb.Sheets("FF_Forecast").Range("A4:AX60000").Copy

Set NewWorkbook = Workbooks.Open(FileName:=WorkbookName,
UpdateLinks:=False)
NewWorkbook.Worksheets.Add(after:=Worksheets(Works heets.count)).Name
= "Forecast" & CStr(count + 1)
NewWorkbook.Sheets("Forecast" & CStr(count +
1)).Range("A4:AX60000").PasteSpecial Paste:=xlPasteValues
NewWorkbook.Names.Add Name:="Start" & CStr(count + 1),
RefersTo:="=Forecast" & CStr(count + 1) & "!$A$6"
NewWorkbook.Sheets("Forecast" & CStr(count + 1)).Range("A1").Select

'call the function here and do all the calculations

qWb.Save
qWb.Close
NewWorkbook.Save
Next count


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default PasteSpecial method for range class failed

Thanks Guys... I found the solution.. I need to close the workbook before I
can open again.

For count = LBound(ID) To UBound(ID)
Set qWb = Workbooks.Open(FileName:=workingDir &
Application.PathSeparator & ncases(ID(count)), UpdateLinks:=False)
qWb.Sheets("FF_Forecast").Range("A4:AX60000").Copy

Set NewWorkbook = Workbooks.Open(FileName:=WorkbookName,
UpdateLinks:=False)
NewWorkbook.Worksheets.Add(after:=Worksheets(Works heets.count)).Name
= "Forecast" & CStr(count + 1)
NewWorkbook.Sheets("Forecast" & CStr(count +
1)).Range("A4:AX60000").PasteSpecial Paste:=xlPasteValues
NewWorkbook.Names.Add Name:="Start" & CStr(count + 1),
RefersTo:="=Forecast" & CStr(count + 1) & "!$A$6"
NewWorkbook.Sheets("Forecast" & CStr(count + 1)).Range("A1").Select

'call the function here and do all the calculations

qWb.Save
qWb.Close
NewWorkbook.Save
#### NewWorkbook.Close
Next count



--
Naga Kiran


"Naga Kiran" wrote:

Hello Gurus,

Attached is a code snippet where I get an error for copying and pasting. I
am trying to open different workbooks and copy certain data and paste it into
a single workbook. however for the first workbook I dont get an error in
pasting values, but for the second workbook excel does copy the values but
cannot paste it. Is there something I am missing in the code.

thank you in advance

For count = LBound(ID) To UBound(ID)
Set qWb = Workbooks.Open(FileName:=workingDir &
Application.PathSeparator & ncases(ID(count)), UpdateLinks:=False)
qWb.Sheets("FF_Forecast").Range("A4:AX60000").Copy

Set NewWorkbook = Workbooks.Open(FileName:=WorkbookName,
UpdateLinks:=False)
NewWorkbook.Worksheets.Add(after:=Worksheets(Works heets.count)).Name
= "Forecast" & CStr(count + 1)
NewWorkbook.Sheets("Forecast" & CStr(count +
1)).Range("A4:AX60000").PasteSpecial Paste:=xlPasteValues
NewWorkbook.Names.Add Name:="Start" & CStr(count + 1),
RefersTo:="=Forecast" & CStr(count + 1) & "!$A$6"
NewWorkbook.Sheets("Forecast" & CStr(count + 1)).Range("A1").Select

'call the function here and do all the calculations

qWb.Save
qWb.Close
NewWorkbook.Save
Next count


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
PasteSpecial method of Range class failed Frank Hayes Excel Programming 6 October 3rd 07 01:34 PM
PasteSpecial Method of Range Class Failed Error a Different Versio SteveC Excel Programming 10 February 16th 07 03:08 PM
PasteSpecial Method of Range Class Failed Error Brian C Excel Programming 5 March 30th 06 08:01 PM
PasteSpecial method of Range class failed windsor Excel Programming 6 October 6th 05 10:16 PM
Run-time error '1004' PasteSpecial Method of Range Class Failed Kevin G[_2_] Excel Programming 1 February 3rd 04 05:01 AM


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