+ Reply to Thread
Results 1 to 3 of 3

Intermittent VBA error on pasting

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-21-2017
    Location
    England
    MS-Off Ver
    2007
    Posts
    409

    Intermittent VBA error on pasting

    Hi I have the following:

    Sub Procedure1()
    'CopynPasteWrkBk:
    Dim InputFile As Workbook
    Dim OutputFile As Workbook
    Dim Inputpath As String
    Dim Outputpath As String '
    
    
    
    
    '## Open both workbooks first:
    Set InputFile = ActiveWorkbook
    Set OutputFile = Workbooks.Open("M:\Bank\z" & InputFile.Sheets("Weeks").Range("I2").Value & " Bank.xlsm")
    
    
    'Now, copy what you want from InputFile:
    InputFile.Sheets("Hours").Range("A3:AL52").Copy
    
    
    
    
    'Now, paste to OutputFile worksheet:
    OutputFile.Sheets("Weekly Hours").Activate
    OutputFile.Sheets("Weekly Hours").Range("B" & Rows.Count).End(xlUp).Offset(1).Select
    ActiveSheet.Paste link:=True
    
    
    
    
    'Close InputFile & OutputFile:
    OutputFile.Close savechanges:=True
    
    
    Application.CutCopyMode = False
    
    Sheets("Rota").Select
    Range("E33").Select
    
    End Sub
    Which works sometimes but then will come up with an error saying Microsoft Excel cannot paste the data error 1004. If I click debug then it highlights:

    ActiveSheet.Paste link:=True
    It's been fine for ages so don't know why I'm suddenly getting an error. If I click end then I can manually paste link with no issue.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Intermittent VBA error on pasting

    Hi,

    Just an untested guess, but try adding the line in red below:
    'Now, paste to OutputFile worksheet:
    OutputFile.Sheets("Weekly Hours").Activate
    OutputFile.Sheets("Weekly Hours").Select
    OutputFile.Sheets("Weekly Hours").Range("B" & Rows.Count).End(xlUp).Offset(1).Select
    ActiveSheet.Paste link:=True
    Lewis

  3. #3
    Forum Contributor
    Join Date
    01-21-2017
    Location
    England
    MS-Off Ver
    2007
    Posts
    409

    Re: Intermittent VBA error on pasting

    Hi thank you.

    I won’t be able to try this until next week but appreciate the suggestion.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Intermittent Table Macro error
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-30-2019, 01:59 PM
  2. Intermittent Unspecified Runtime Error
    By Rclay11541 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-28-2016, 05:05 PM
  3. Variable in a Range Function - Intermittent Error
    By rsmithline in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-21-2015, 09:35 AM
  4. Intermittent error with email generation macro - pasting from excel to outlook mail
    By oenleunc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-15-2014, 05:46 AM
  5. [SOLVED] Intermittent Error 1004 on Selection.PasteSpecial
    By BeachRock in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 10-21-2012, 01:23 AM
  6. Intermittent Runtime Error when inserting picture
    By vamosj in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-20-2009, 04:36 AM
  7. Insert Pic Intermittent runtime error
    By vamosj in forum Access Programming / VBA / Macros
    Replies: 0
    Last Post: 04-19-2009, 07:01 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1