+ Reply to Thread
Results 1 to 7 of 7

PasteSpecial causing RunTime error 1004 & autofill doesn't stop at last line

  1. #1
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    639

    PasteSpecial causing RunTime error 1004 & autofill doesn't stop at last line

    I am attempting to add a line and insert a VLookup for all the account numbers in column A (the Openworkbooks will be changed to filter through a list on a loop opnce I have this so the row count will vary). Currently the autofill isn't stopping and completing the whole of Column B (which needs to be addressed as it will paste #N/A all down the page) but the main issue is copying the column and pasting values instead of the formula as when this is closed it can't have formulas in it.

    Can anyone suggest any help with the code please?

    Please Login or Register  to view this content.
    Last edited by Sc0tt1e; 10-24-2014 at 08:12 AM.

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: PasteSpecial causing RunTime error 1004 & autofill doesn't stop at last line

    You're calculating lastrow before you open the workbook, so you get the last row (presumably) of your lookup table instead - which you probably do want to use for your formula. Try this:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  3. #3
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    639

    Re: PasteSpecial causing RunTime error 1004 & autofill doesn't stop at last line

    OK Romperstomper (Not named after the Australian film is it?) I have amended code, can you see any flaws (there are 377 files in the directory so I'd like to get the code right before testing/running it)?

    Please Login or Register  to view this content.

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: PasteSpecial causing RunTime error 1004 & autofill doesn't stop at last line

    Yes, that's where the name comes from.

    A couple of issues in there - I'd suggest this:
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    639

    Re: PasteSpecial causing RunTime error 1004 & autofill doesn't stop at last line

    Early Russell Crowe if I'm not mistaken. A very raw and realistic film, not really sure how to approach the subject matter in this forum though.

    What's the .Value2 = .Value2 all about

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: PasteSpecial causing RunTime error 1004 & autofill doesn't stop at last line

    It replaces the formula with the calculated values (the equivalent of the Copy & PasteSpecial you had).

  7. #7
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    639

    Re: PasteSpecial causing RunTime error 1004 & autofill doesn't stop at last line

    Cool, learning loads today

    I've made one amendment, don't think it should affect anything but wanted to make sure it chose the right sheet incase someone had saved it with an alternative sheet open.

    Please Login or Register  to view this content.

+ 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. Runtime error 1004 @ every 2nd run @ pastespecial
    By BlauePflanze in forum Excel General
    Replies: 0
    Last Post: 10-21-2014, 03:55 AM
  2. [SOLVED] Pastespecial xlPasteValues Runtime Error 1004
    By natefarm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-05-2013, 01:37 PM
  3. runtime error 1004 pastespecial method of range class failed
    By JillCALIBRE in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-30-2009, 11:31 AM
  4. Runtime Error 1004 when trying to PasteSpecial
    By Phil Davis in forum Excel General
    Replies: 2
    Last Post: 02-16-2006, 06:10 PM
  5. runtime error 1004 pastespecial method of range class failed
    By dreamz in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-03-2006, 10:57 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