+ Reply to Thread
Results 1 to 5 of 5

Swapping Selected Range of Cells with Another Selection

  1. #1
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    854

    Swapping Selected Range of Cells with Another Selection

    I'm wondering if someone could help with what may or may not be a simple request.


    I'd like to be able to swap a Range of Selected Cells with another Selected Range.

    For example; Select Range B5:B7 and then also F9:F11 And then swap the values in those cells/range.

    The columns and rows is not fixed, so I would be swapping these selected ranges throughout the document.


    Thanks

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Swapping Selected Range of Cells with Another Selection

    Complexity of code will depend on how flexible it has to be.

    You'll need to give more detail than what you provided.

    1. Are you only swapping values? Or do you need to swap formula, format, etc as well?
    2. Is swapped range always going to have same dimension? (i.e. first range row & column count = second range row & column count). In another word, 1 to 1 swap.
    3. Will it be always within same workbook and/or worksheet?

    If it's values only and dimension is same between two ranges and only from same workbook... it will be fairly straight forward and simple code.
    Otherwise, as you add more flexibility, more complex the code will be.

    But really, this sort of flexible operation is best left out of VBA and done manually.
    Simple key combo along with some blank sheet to store values will make swapping easy.
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

  3. #3
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,775

    Re: Swapping Selected Range of Cells with Another Selection

    Try
    Please Login or Register  to view this content.
    For this to work the 2 selections must be the same size & shape.

  4. #4
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Swapping Selected Range of Cells with Another Selection

    You may try something like this...

    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  5. #5
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,261

    Re: Swapping Selected Range of Cells with Another Selection

    Let there be even more choice ... ... with pop-up menu ... (see additionally: https://msdn.microsoft.com/en-us/lib...fice.14).aspx)

    Areas do not have to be equivalent, at most, strange things will come out of it.
    Select two areas to swap and select the menu from the right mouse button - first position.

    1. In 'ThisWorkbook' module:
    Please Login or Register  to view this content.
    2. In Standard module:
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by mjr veverka; 04-02-2018 at 04:26 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro to shift data in selected range to top of selection
    By Justair07 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-30-2017, 10:26 AM
  2. [SOLVED] Pasting an image into selected merged cells. VBA to size automatically to selected range
    By DCC_PD in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-28-2015, 09:57 AM
  3. [SOLVED] Issues Swapping out a VBA-recorded range with a variable-based range
    By lordterrin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-21-2014, 02:37 PM
  4. Loop backwards through selected range - delete entire row from selected cells
    By scottbass in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-20-2014, 09:21 AM
  5. [SOLVED] Populate selected cells from combo box selection
    By Bravo33 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-12-2013, 03:09 AM
  6. Macro to select cells and then new selection from selected cells
    By Rewop Eilsel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-06-2006, 11:25 AM
  7. [SOLVED] Range Selection-Once the range is selected,
    By Steve C in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-09-2006, 02:55 PM

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