+ Reply to Thread
Results 1 to 4 of 4

Swap ranges within the same row

  1. #1
    Registered User
    Join Date
    04-07-2015
    Location
    San Jose, California
    MS-Off Ver
    2011
    Posts
    1

    Swap ranges within the same row

    Issue: I'm trying to swap ranges (4 adjacent cells) within a row.

    For example: My spreadsheet contains student data - each student has a primary guardian and a secondary guardian. In some cases the primary guardian is listed in the secondary guardian column and needs to be swapped with the secondary guardian which is listed in the primary column. I have a column that returns a true/false value when this is the case and a change needs to be made.

    I'm looking for code that does the following:
    1) look at column B - skip if value is "True" , execute the following commands if value is "False"
    2) if value in column B = "False" then copy cells C3:F3 and swap with H3:K3

    I've been playing with the following code:

    Sub SwapCells()

    Dim start1 As Range
    Dim start2 As Range
    Dim finish1 As Variant
    Dim finish2 As Variant


    Set start1 = Application.InputBox(Prompt:="Please Select a Range", Title:="InputBox Method", Type:=8)
    Set start2 = Application.InputBox(Prompt:="Please Select a Range", Title:="InputBox Method", Type:=8)
    finish1 = start1.Value
    finish2 = start2.Value



    If start1.Cells.Count <> start2.Cells.Count Then
    MsgBox " Please select a matching number of cells"
    Exit Sub
    Else:

    start1.Value = finish2
    start2.Value = finish1

    End If


    End Sub

    Any help is appreciated! Thanks!

  2. #2
    Registered User
    Join Date
    06-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    51

    Re: Swap ranges within the same row

    Might not be the most efficient, but try this.


    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Swap ranges within the same row

    Maybe:

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,585

    Re: Swap ranges within the same row

    Try this Code
    Please Login or Register  to view this content.

+ 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. Last name First name swap
    By Hektor in forum Excel General
    Replies: 3
    Last Post: 10-25-2011, 05:19 PM
  2. Swap if
    By VBisgreat in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-21-2011, 04:28 PM
  3. Swap Two Cell Ranges?
    By papagorgio in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-26-2010, 01:46 PM
  4. Swap identical ranges of cell values
    By CCArtsAlliance in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-25-2010, 10:54 PM
  5. [SOLVED] swap
    By Gary in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 08-01-2006, 10:55 PM

Tags for this Thread

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