Consulting

Results 1 to 7 of 7

Thread: Run-time error '1004' using PasteSpecial

  1. #1

    Run-time error '1004' using PasteSpecial

    Hi folks,

    Having trouble with some simple code. I am pasting some data from the clipboard.

    I receive the error msg: Run - time error '1004' PasteSpecial Method of range class failed
    [VBA]
    Worksheets("Paste Sheet").Range("AX2:AZ50").Clear
    Worksheets("Paste Sheet").Cells(2, 50).PasteSpecial (xlAll)
    [/VBA]

    xlAll has the value -4104

    I am definately coping the data before I paste it.

    I have tried other options including selecting and activating the sheet first.

    Any one have any ideas plz?

    Thanks a million

    ger

  2. #2
    Administrator
    2nd VP-Knowledge Base
    VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    I think it might be because you clear cells before using the PasteSpecial method. If you record a marco and copy a set of cells then delete others, you lose what you copied even if what you deleted had no affect on those copied cells. So there is no range to paste because it was discarded.

    Hope (I'm right and) this helps




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  3. #3
    That works thanks a million.... but why does the same error appear when i use the following code:

    [VBA]
    Worksheets("Paste Sheet").Range("BC2").Select
    ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:= _
    False
    [/VBA]

    Is it because im selecting the cell BC2 first?

    The reason I am using a paste special text only here as on one other PC i have tested my code on the data I am copying (from a CSV file) is sometimes put in as a picture!

    Any help again much appreciated!

  4. #4
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Quote Originally Posted by gersemale
    [VBA]
    Worksheets("Paste Sheet").Range("BC2").Select
    ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon:= _
    False
    [/VBA]

    Is it because im selecting the cell BC2 first?

    The reason I am using a paste special text only here as on one other PC i have tested my code on the data I am copying (from a CSV file) is sometimes put in as a picture!

    Any help again much appreciated!
    If the cell is to be formatted as text and whatever you are copying is not already formatted as text, then I think that you cannot format the cell as you are pasting, it has to be formatted before doing so.

    [VBA]
    Worksheets("Paste Sheet").Range("BC2").Select
    Selection.NumberFormat = "@" 'Formats cell to text
    ActiveSheet.PasteSpecial Link:=False, DisplayAsIcon:= False


    'Now if the cell that you copied is already text formatted, then:

    Worksheets("Paste Sheet").Range("BC2").Select
    ActiveSheet.PasteSpecial Paste:=xlFormats, Link:=False, DisplayAsIcon:= False
    [/VBA] This should do it
    HTH




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  5. #5
    Hey, thanks for your reply however I am still experiencing the same problem. Same error msg appearing.

    Further note that PasteSpecial(xlAll) works on my PC but not on another with the same version of excel!

    Any further ideas?

  6. #6
    VBAX Expert Shazam's Avatar
    Joined
    Sep 2005
    Posts
    530
    Location
    Hi gersemale,

    I tried all the codes that was provided on this thread and I do get the same error BUT then I named my worksheet tab Paste Sheet and all the codes works fine now. Maybe just name your worksheet Paste special.

  7. #7
    Thanks Shazam!

Posting Permissions

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