+ Reply to Thread
Results 1 to 3 of 3

Copying multiple ranges

Hybrid View

  1. #1
    Registered User
    Join Date
    04-18-2012
    Location
    Norway, Ålesund
    MS-Off Ver
    Microsoft office 2010/2013
    Posts
    51

    Copying multiple ranges

    Hey, I have a spreadsheet where i want to be able to copy multiple ranges at one time (like holding ctrl down when you copy normally) with VBA, here are the following ranges:

    B1:F12

    B14:Cells(15, 3 + Range("G1"))

    B18:F27

    B29:Cells(31,3+Range("G1"))

    B34:F45

    B49:H49

    Can anyone help me making the code, I think it is not that hard to do, but I have never done it before so...

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Copying multiple ranges

    Hello Buster^,

        Set Rng1 = Range("B14", Cells(15, 3 + Range("G1"))
        Set Rng2 = Range("B29", Cells(31, 3 + Range("G1"))
        Set Rng3 = Union( Range("B1:F12, B18:F27, B34:F45, B49:H49"), Rng1, Rng2)
    
        Rng3.Copy
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    04-18-2012
    Location
    Norway, Ålesund
    MS-Off Ver
    Microsoft office 2010/2013
    Posts
    51

    Re: Copying multiple ranges

    Thanks for helping me, but I am getting a runtime 1004 error:"can not execute this command on multiple samples simultaneously", the debugging is marking the rng3.copy

+ 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