Run Time Error '1004' PasteSpecial method of Range class failed

Kittrell

New Member
Joined
Oct 23, 2017
Messages
2
Okay, so this one is driving me batty. Very simple, I am pasting data from one workbook to another. I am doing this several times as I have to pull the data under certain assigned accounts. I receive the above error for this line of code, Selection.PasteSpecial Paste:=xlPasteValues. I have read through countless threads with this issue and the only conclusion I have come to is that possibly this bit of code that is running between the copy and paste is clearing the clipboard:

Code:
    Windows("DC OIF " & " " & Format(Now(), "MMDDYY")).Activate
    Sheets("ZOTCM DD").Select
        Set WS = ActiveSheet
        For Each Cell In WS.Columns(1).Cells
        If IsEmpty(Cell) = True Then Cell.Select: Exit For
        Next Cell
    'Select next available empty cell in column A

Full code

Code:
Sub PER_OIF_ZOTCM_Update()'
'ZOTCM Update - Ctrl + Shift + Z
'


'
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With
    
    Range("A2").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows("DC OIF " & " " & Format(Now(), "MMDDYY")).Activate
    Sheets("ZOTCM DD").Select
        Set WS = ActiveSheet
        For Each Cell In WS.Columns(1).Cells
        If IsEmpty(Cell) = True Then Cell.Select: Exit For
        Next Cell
    'Select next available empty cell in column A
    
    Selection.PasteSpecial Paste:=xlPasteValues
    'Paste SAP data
    
    Range("A2:T2").CurrentRegion.Sort key1:=Range("Q2"), order1:=xlAscending, Header:=xlGuess
    'Sort SAP data
    
    ActiveWorkbook.RefreshAll
    ActiveWorkbook.RefreshAll
    ActiveWorkbook.RefreshAll
    'Refresh Workbook
    
    Sheets("Summary").Select
    
    
End Sub

Any thoughts? Since I need it to select the next empty cell to paste the data, as not to overwrite what is already there, I am not sure how I could remove or move this bit of code.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Those select and windows syntax can be gotten rid of but for that you need to describe what you are trying to achieve.

Instead of looping you can use:
Code:
Sheets("ZOTCM DD").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Select
 
Upvote 0
It ended up being that the tabs were hidden. So I wrote in code to unhide and rehide the tabs, problem solved!
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,316
Members
452,634
Latest member
cpostell

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