PasteSpecial does not work in VBA code

  • I have attached the code where I am trying to select a user range thru a subroutine and use this generically to copy from one sheet and paste it to another sheet I am using pastespecial as I want to copy only the format and not the values. The code dos not work and gets stuck at highlighted line in the attachment.the message i get is Run time error 1004 . pasteSpecial method of range class failed Any suggestions to correct this error?





    The crux of the problem

    • First sub selects a range to be copied in Sjheet1 as specified by the user
    • Second subroutine activates a sheet “COGNI”: and tried to paste into a location specified by user thru input box
    • The macro is stuck at highlighted point
  • Re: Pastespecial does not work in VBA code


    I would suggest you do something like this:

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Re: Pastespecial does not work in VBA code


    Thanks for the quick response. While running it I get the error "Compile error :object required". Am I missing something?

  • Re: Pastespecial does not work in VBA code


    Sorry, I forgot to change a variable:

    Code
    UserRange.PasteSpecial xlPasteFormats


    should be

    Code
    PasteRange.PasteSpecial xlPasteFormats

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!