Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
setoFairfax
 
Posts: n/a
Default Excel 1004 Error When Pasting Special W/ Macro

Hi all,
I'm looking for some help with this macro...it has me really confused
because it was working earlier, but now it hangs on this line of code (it is
asterisked below)

Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

This macro runs when the workbook opens and copies the contents of one
sheet and pastes only the values to another sheet. The range that is being
copied from and pasted to are both the same size. I have also tried this by
selecting the upper-leftmost cell in the area I want to paste to but it has
the same effect. Please help!

The exact error message is;
Runtime Error '1004': PasteSpecial method Range of class failed

__________________________________________________ ______________
Private Sub Workbook_Open()
Sheets("Permit Records").Select
Range("A5").Select
ActiveWindow.ScrollRow = 493
Range("A5:M504").Select
ActiveWindow.ScrollRow = 6
Selection.Copy
Range("A1").Select
Sheets("Final Inspection").Select
ActiveSheet.Unprotect Password:="XXXX"
Range("A5").Select
ActiveWindow.ScrollRow = 492
Range("A5:M504").Select
ActiveWindow.ScrollRow = 5
***Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Range("A1").Select
ActiveSheet.Protect Password:="XXXX", DrawingObjects:=True,
Contents:=True, Scenarios:=True
Sheets("Permit Records").Select
Application.CutCopyMode = False
Range("A1").Select
End Sub
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

You do a lot of selecting in your code. For the most part, you don't have to
select something to work with it.

Option Explicit
Private Sub Workbook_Open()

Worksheets("final inspection").Unprotect Password:="XXXX"

Worksheets("Permit Records").Range("A5:M504").Copy

With Worksheets("final inspection")
.Range("A5").PasteSpecial _
Paste:=xlValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
.Protect Password:="XXXX", DrawingObjects:=True, _
Contents:=True, Scenarios:=True
Application.Goto .Range("a1"), Scroll:=True
End With

With Worksheets("Permit Records")
Application.Goto .Range("a1"), Scroll:=True
End With
Application.CutCopyMode = False

End Sub

(Did I protect/unprotect the correct worksheet? I got kind of confused.)

setoFairfax wrote:

Hi all,
I'm looking for some help with this macro...it has me really confused
because it was working earlier, but now it hangs on this line of code (it is
asterisked below)

Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

This macro runs when the workbook opens and copies the contents of one
sheet and pastes only the values to another sheet. The range that is being
copied from and pasted to are both the same size. I have also tried this by
selecting the upper-leftmost cell in the area I want to paste to but it has
the same effect. Please help!

The exact error message is;
Runtime Error '1004': PasteSpecial method Range of class failed

__________________________________________________ ______________
Private Sub Workbook_Open()
Sheets("Permit Records").Select
Range("A5").Select
ActiveWindow.ScrollRow = 493
Range("A5:M504").Select
ActiveWindow.ScrollRow = 6
Selection.Copy
Range("A1").Select
Sheets("Final Inspection").Select
ActiveSheet.Unprotect Password:="XXXX"
Range("A5").Select
ActiveWindow.ScrollRow = 492
Range("A5:M504").Select
ActiveWindow.ScrollRow = 5
***Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Range("A1").Select
ActiveSheet.Protect Password:="XXXX", DrawingObjects:=True,
Contents:=True, Scenarios:=True
Sheets("Permit Records").Select
Application.CutCopyMode = False
Range("A1").Select
End Sub


--

Dave Peterson
  #3   Report Post  
setoFairfax
 
Posts: n/a
Default

Dave, thank you so much - it works perfectly now! I'm going to try this
method with my other macros - it looks much more efficient than what I had
before.

"Dave Peterson" wrote:

You do a lot of selecting in your code. For the most part, you don't have to
select something to work with it.

Option Explicit
Private Sub Workbook_Open()

Worksheets("final inspection").Unprotect Password:="XXXX"

Worksheets("Permit Records").Range("A5:M504").Copy

With Worksheets("final inspection")
.Range("A5").PasteSpecial _
Paste:=xlValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
.Protect Password:="XXXX", DrawingObjects:=True, _
Contents:=True, Scenarios:=True
Application.Goto .Range("a1"), Scroll:=True
End With

With Worksheets("Permit Records")
Application.Goto .Range("a1"), Scroll:=True
End With
Application.CutCopyMode = False

End Sub

(Did I protect/unprotect the correct worksheet? I got kind of confused.)

setoFairfax wrote:

Hi all,
I'm looking for some help with this macro...it has me really confused
because it was working earlier, but now it hangs on this line of code (it is
asterisked below)

Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

This macro runs when the workbook opens and copies the contents of one
sheet and pastes only the values to another sheet. The range that is being
copied from and pasted to are both the same size. I have also tried this by
selecting the upper-leftmost cell in the area I want to paste to but it has
the same effect. Please help!

The exact error message is;
Runtime Error '1004': PasteSpecial method Range of class failed

__________________________________________________ ______________
Private Sub Workbook_Open()
Sheets("Permit Records").Select
Range("A5").Select
ActiveWindow.ScrollRow = 493
Range("A5:M504").Select
ActiveWindow.ScrollRow = 6
Selection.Copy
Range("A1").Select
Sheets("Final Inspection").Select
ActiveSheet.Unprotect Password:="XXXX"
Range("A5").Select
ActiveWindow.ScrollRow = 492
Range("A5:M504").Select
ActiveWindow.ScrollRow = 5
***Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Range("A1").Select
ActiveSheet.Protect Password:="XXXX", DrawingObjects:=True,
Contents:=True, Scenarios:=True
Sheets("Permit Records").Select
Application.CutCopyMode = False
Range("A1").Select
End Sub


--

Dave Peterson

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
Saving Excel using Macro mrbalaje Excel Discussion (Misc queries) 4 April 20th 05 02:32 PM
Button fails to call macro when open an Excel via Intranet tigertax Excel Discussion (Misc queries) 1 April 12th 05 10:21 AM
Macro not working with Excel 2003 Fernando Gomez Excel Discussion (Misc queries) 1 December 16th 04 12:19 AM
excel macro inconsistency JM Excel Discussion (Misc queries) 2 December 9th 04 01:13 AM
Paste Special in a macro CMAC Excel Worksheet Functions 2 December 6th 04 10:19 PM


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