r/t error 1004

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,486
In my app I' have previouly used similar code but for some reason I'm getting a r/t error 1004 as marked below. Can anyone spot the problem?
TIA,
Jim

Code:
Sub TransferToNewPricesOnlySheet()
    With Sheets("WorkingReport")
        .Activate
        .Unprotect Password:="john"
    Lr = Range("A" & Rows.Count).End(xlUp).Row
        .Range("A7:L" & Lr).Copy
    End With
    With Sheets("OnlyNewPrices").Range("A7")
    .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    .PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _     'Getting r/t 1004
        SkipBlanks:=False, Transpose:=False
    End With
    ActiveSheet.Protect Password:="john"
    Application.CutCopyMode = False
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Greetings and a Howdy from Arizona Jim,

I'm on a "just barely electric" old laptop running xl2000, and the code as shown worked fine for me. Sorry not of more help :(

Mark
 
Upvote 0
Hi,

What is the error message itself, that should give us a clue?

Do you have any Worksheet_Change / Workbook_SheetChange etc.. event handler code which would cause a problem such as clearing the clipboard / protecting the sheet, etc... when the OnlyNewPrices worksheet's change event is raised on the first pastespecial?
 
Upvote 0
My WorkingReport Sheet Code has the following attached to it:

Code:
Private Sub CommandButton1_Click()
If Me.CommandButton1.Caption = "Based on Group - Show ONLY Stores With Price Changes" Then
Range("L7").AutoFilter Field:=12, Criteria1:="=CHG", Operator:=xlOr, _
        Criteria2:="=YES"
Me.CommandButton1.Caption = "Remove Price Change Filter"
Else
Range("L7").AutoFilter Field:=12
Me.CommandButton1.Caption = "Based on Group - Show ONLY Stores With Price Changes"
End If
Range("B4").Select
End Sub

Private Sub Worksheet_Calculate()
If Range("L4").Value = 0 Then
Me.CommandButton1.Visible = False
Else
Me.CommandButton1.Visible = True
End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Target.Address = "$B$4" Then
Exit Sub
End If
Application.EnableEvents = False
Application.ScreenUpdating = False
If Target.Address = "$B$4" Then
If Range("B4").Value = "All" Then
    Range("A7").CurrentRegion.AutoFilter Field:=13
    Else
    Range("A7").CurrentRegion.AutoFilter Field:=13, Criteria1:=Range("B4").Value, Operator:=xlAnd
    End If
End If
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

My OnlyNewPrices sheet has NO event code attached..
 
Upvote 0
Greetings Jim,

I have now tried this in 2003, and still no hitches. Further - attempted to replicate the filtering, even tried protecting the destination sheet; am still unable to raise an error.

Have you tried rem'ing the first PasteSpecial, to isolate/see if its the second one that is being balked at?

Rich (BB code):
    With Sheets("OnlyNewPrices").Range("A7")
'    .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    .PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
        'Getting r/t 1004

Mark
 
Upvote 0
Hi Jim,

What is the error message that accompanies the error number? Knowing this would be really helpful.

Is there any event handler code in the ThisWorkbook class module?
Are there any merged cells anywhere?


Also, I don't think it will have an impact but this line of code:
Rich (BB code):
Lr = Range("A" & Rows.Count).End(xlUp).Row

should read as:
Rich (BB code):
Lr = .Range("A" & .Rows.Count).End(xlUp).Row
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top