Swapping Two Cells

by Allen Wyatt
(last updated May 27, 2017)

3

Adam needs to swap the contents of two cells and wonders if there is a way to do it without doing a three-step move.

There are actually a few ways you can accomplish this task, depending on how the two cells are situated in relation to each other. If the two cells are adjacent, then you can use the mouse to make the swap:

Select the first cell (for instance, cell C3). Then, hold down the Shift key as you drag one of the cell edges over the cell you want to swap with (for instance, cell D3). This takes a bit of practice, but as you move the mouse pointer around the cell you want to swap with, you'll see "heavy" markers appear that indicate where where the swap will occur.

In reality, what is happening is that you are indicating where you want the original cell (C3) moved. Since you want to swap with cell D3, you want to continue holding down the Shift key until you see the heavy marker appear to the right of cell D3. (See Figure 1.)

Figure 1. The "heavy" marker indicates where the original cell will be copied.

Since the original cell is being moved to the right, cell D3 moves to the left to fill where cell C3 used to be. The result is that cells C3 and D3 are swapped.

If you don't want to use the mouse and keyboard together, you may find these steps just a bit easier:

  1. Select the right-most cell you want to swap (in this case, cell D3).
  2. Press Ctrl+X. This cuts the cell to the Clipboard, and you should see "marching ants" around cell D3.
  3. Select the left-most cell you want to swap (in this case, cell C3).
  4. Press Ctrl++ (that's Ctrl plus the plus sign, which is the same as pressing Shift+Ctrl+=).

A third way to swap adjacent cells is to select the two of them and then use the sorting capabilities of Excel to sort just the two selected cells. You may need to play with sorting ascending or descending, but you should be able to eventually get the cells in the order desired.

If your cells are not adjacent to each other, then you'll need to rely on a macro to do the swapping. The following macro will swap two non-adjacent cells or two adjacent cells; it doesn't matter.

Sub SwapCells()
    Dim sHolder As String

    If Selection.Cells.Count = 2 Then
        With Selection
            sHolder = .Cells(1).Formula
            If .Areas.Count = 2 Then  ' Cells selected using Ctrl key
                .Areas(1).Formula = .Areas(2).Formula
                .Areas(2).Formula = sHolder
            Else                      ' Adjacent cells are selected
                .Cells(1).Formula = .Cells(2).Formula
                .Cells(2).Formula = sHolder
            End If
        End With
    Else
        MsgBox "Select only TWO cells to swap", vbCritical
    End If
End Sub

Note that the macro only swaps what is in the cells, not cell formatting. (The earlier mouse and keyboard approaches for use with adjacent cells swapped formatting as well as cell contents.)

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (1664) applies to Microsoft Excel 2007, 2010, 2013, and 2016.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Formatting Endnote Reference Marks

The reference marks used for endnotes are, by default, formatted "good enough" for most people. If you are one of those for ...

Discover More

Distributing Table Rows Evenly

If you've adjusted the height of your table and the rows within the table, you might want to later return all those rows to a ...

Discover More

Finding Where Templates Are Stored

The first step in modifying templates is to find out where they are stored on your system. Here's the easiest way to figure ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (ribbon)

Quickly Entering Data

Excel includes a handy shortcut for entering data that is similar to whatever you entered in the cell above your entry point. ...

Discover More

Copying Cells to Fill a Range

Excel provides two really helpful shortcuts you can use to fill a range of cells, either horizontally or vertically. These ...

Discover More

Synchronizing Lists

Two lists of similar data can be challenging to synchronize. Here are some ways that you can align data in two different ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is five less than 5?

2017-05-28 19:41:44

Henry Noble

Method 1, Shift+Drag, appears to work equally well to the right or left and up or down.


2017-05-28 18:42:55

John Allott

You need to also consider if the cells have any dependent formulas. The manual system applies a CUT method, therefore, any references will remain.

The macro version is a COPY VALUES


2017-05-27 14:51:57

John Fistere

It is useful to know that the first method of swapping two cells (using mouse and keys) works for swapping a column of data, whether it be a specific length column or the entire spreadsheet column. It also works for rows of data.

John Fistere


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.