Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 237
Default Paste method of worksheet class failed error

This is a code stored in my Personal.Xls:

wb.Worksheets(1).Range("C5").Select
ActiveSheet.Paste

When I run the below code, I get the debug error "Paste
method of worksheet class failed" on the above part of the
code. What should I do to get it to not give me this
error?

Dim wb As Workbook
If MsgBox("Would you like to Import Data?", vbYesNo) =
vbNo Then
Exit Sub
End If
On Error Resume Next
Set wb = Workbooks("Stats Manager.xls")
On Error GoTo 0
If wb Is Nothing Then Set wb = Workbooks.Open("P:\Stats
Manager.xls")

With Worksheets(1)
Set rng = .Range("A4:Z100")
Set rng1 = .Range("A4:AZ4")
End With
res = Application.Match("Ext", rng1, 0)
If Not IsError(res) Then
Set rng2 = rng1(1, res)
rng.Sort Key1:=rng2, Order1:=xlAscending, _
Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
End If

wb.Worksheets(1).Range("C5").Select
ActiveSheet.Paste

Range("B5:AZ100").Select
Range("AZ5").Activate
With Selection
.HorizontalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With
Range("A2:AZ3").Select

MsgBox "Data Imported Successfully!", vbOKOnly

If MsgBox("Would you like to Save Workbook?", vbYesNo) =
vbNo Then
Exit Sub
End If
ActiveWorkbook.Save
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Paste method of worksheet class failed error

1. Your Paste code line is not as explicit as that required. We should
evidently, use something like :-
'-----------------------------------------------------------------------------
ActiveSheet.Paste Destination:=Worksheets(1).Range("C5")
'-----------------------------------------------------------------------------

Seems like a "belt and braces" approach - but it is probably "
feature, not a bug". Despite this, I do get inexplicable problems wit
Paste at times. Generally find that the following produces bette
results than using Select or Activate:-

'----------------------------------------------------------------------------
Application.Goto reference:=wb.Worksheets(1).Range("C5")
'----------------------------------------------------------------------------

--
Message posted from http://www.ExcelForum.com

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
Run-time error '1004': AutoFill method of Range class failed murkaboris Excel Discussion (Misc queries) 10 April 16th 09 09:06 PM
Error 1004 Copy method of worksheet class failed Ayo Excel Discussion (Misc queries) 3 March 28th 08 02:05 PM
Run-Time error '1004' : Select method of Range class failed [email protected] Excel Discussion (Misc queries) 3 March 9th 07 01:36 PM
error 1004 Select method of Range class failed J.E. McGimpsey Excel Programming 1 September 12th 03 07:42 PM
Error Excel: 1004 SaveAs method of Workbook class failed sebastien Excel Programming 0 August 13th 03 09:59 AM


All times are GMT +1. The time now is 09:08 AM.

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"