+ Reply to Thread
Results 1 to 4 of 4

Sub to Copy and Paste a Range of Cells

Hybrid View

  1. #1
    Registered User
    Join Date
    07-06-2010
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Sub to Copy and Paste a Range of Cells

    This should be really simple, but I keep getting error messages when I try to paste. Perhaps you can help?
    I first want to select a range of cells with the mouse.
    Then I want an ImputBox to ask me where to Paste to.
    I select a cell with the mouse and press OK.
    At this stage I get an error message, but I am not sure why?
    I have tried each of the bits of code in remarks, but they all give an error message.
    Please could you keep it simple and explain why mine does not work.



    Sub Copy_And_Paste()
    Dim CopyRange As Range
    Dim PasteRange As Range
    
    Set CopyRange = Selection
    
    CopyRange.Select
    
      Selection.Copy
    
        Set PasteRange = Application.InputBox(prompt:="Select Where to Paste to", Type:=8)
    
    Rem *** It works up to here ***
    Rem *** I have tried the following ***
     
    ' PasteRange.Select
    
    ' CopyRange.Paste
    
    ' Selection.Paste
    
    ' Selection.PasteSpecial Paste:=xlValues
    ' Application.CutCopyMode = False
    
    End Sub
    Last edited by FrankB2050; 07-07-2010 at 09:49 AM.

  2. #2
    Registered User
    Join Date
    07-06-2010
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Sub to Copy and Paste a Range of Cells

    'PasteRange.Select' Works, but 'PasteRange.Paste' gives
    Run Time Error '438'
    Object doesn't support this property or method

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Sub to Copy and Paste a Range of Cells

    This works for me.

    Sub Copy_And_Paste()
    
        Dim CopyRange As Range
        Dim PasteRange As Range
    
        On Error Resume Next
        Set CopyRange = Selection
        Set PasteRange = Application.InputBox(prompt:="Select Where to Paste to", Type:=8)
        If Not PasteRange Is Nothing Then
            CopyRange.Copy PasteRange
        End If
    
    End Sub
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    07-06-2010
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Sub to Copy and Paste a Range of Cells

    Many thanks Andy - And so neat and simple.

    It works for me too.

    Thanks Again

    Frank

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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