+ Reply to Thread
Results 1 to 4 of 4

Paste Values Without Selecting the destination range

Hybrid View

  1. #1
    Registered User
    Join Date
    05-23-2012
    Location
    Colorado
    MS-Off Ver
    Excel 2010
    Posts
    3

    Paste Values Without Selecting the destination range

    I'd like to make my code just a little more succinct and in the process speed up its execution. I have a lot of copy/paste iterations. I'd like to be able to do the paste part without actually activating or selecting the destination range. Here is my code so far:

    Private Sub copyPaste(ByVal wbSource As String, ByVal wbDest As String, thisRange As String, ByVal wsDest As Worksheet)
    
        Windows(wbSource).Activate
        Range(thisRange).Copy
        
        Windows(wbDest).Activate
        wsDest.Activate
        Range(thisRange).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    
    End Sub
    It's the last four lines that I'd like to condense into possibly a singe line or maybe two. Something along the lines of this would be ideal (except that this doesn't work as written):
        Windows(wbDest).wsDest.Range(thisRange).PasteSpecial ...
    Anyone have any suggestions? Thanks.

  2. #2
    Registered User
    Join Date
    04-20-2012
    Location
    New York, NY
    MS-Off Ver
    Excel 2013, 2010, 2007, 2003
    Posts
    99

    Re: Paste Values Without Selecting the destination range

    To my knowledge you cannot paste without defining a range to paste into
    SPARTAN
    Please click the * if my solution helped

  3. #3
    Forum Contributor
    Join Date
    01-24-2011
    Location
    Sheppey
    MS-Off Ver
    Excel 2010
    Posts
    239

    Re: Paste Values Without Selecting the destination range

    To speed up my code I use these two commands at the front, but don't forget to turn them back on again at the end.
    Application.ScreenUpdating = False
    This stops the screen from flick around as the code is running and
    Application.Calculation = xlCalculationManual
    which stops all the individual calculations while the code is running.

  4. #4
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,308

    Re: Paste Values Without Selecting the destination range

    Possibly with...
        Dim vCopy As Variant
        
        vCopy = Workbooks(wbSource).Range(thisRange).Value2
        Workbooks(wbDest).Range(thisRange) = vCopy

+ 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